There is a special loop for arrays in Php (including for the associative arrays), it is called foreach.
Read MORE HERE
You should use foreach if you want to see the values in associative arrays (and not only for associative arrays
but for simple ones as well) .
Here's an example:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP - foreach Loop</title>
</head>
<body>
<?php
$names = [
'Alex' => 'Alexi',
'Connor' => 'McGregor',
'Habib' => 'Nurmagomedov',
'John' => 'Cena',
];
foreach ( $names as $name ) {
echo $name . '<br>';
}
?>
</body>
</html>
Also, it is a good practice to name the array in plural and the value in singular.
For example if the array is named $names, the values to be shown (printed) should be named $name.
And this is the code if you want to see the keys and the values:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP - For Loop</title>
</head>
<body>
<?php
$names = [
'Alex' => 'Alexi',
'Connor' => 'McGregor',
'Habib' => 'Nurmagomedov',
'John' => 'Cena',
];
foreach ( $names as $key => $name ) {
echo "$key $name" . '<br>';
}
?>
</body>
</html>