Using foreach with Associative Arrays in PHP


Iterate over an associative array with foreach.

Source Code

$ages = ['Peter' => 41, 'John' => 30, 'Jane' => 29];
foreach ($ages as $name => $age) {
    echo "$name is $age years old.n";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments