php loop associative array
snippet in php

php loop associative array

user1762

<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

foreach($age as $x => $x_value) {
    echo "Key=" . $x . ", Value=" . $x_value;
    
}

//Key=Peter, Value=35
//Key=Ben, Value=37
//Key=Joe, Value=43
 

php foreach associative array

user1048

$arr = array(
  'key1' => 'val1',
  'key2' => 'val2',
  'key3' => 'val3'
);

foreach ($arr as $key => $val) {
  echo "$key => $val" . PHP_EOL;
}