key value array in php code example
Example 1: array associativo php
<?php
$age = array("Samy"=>"35", "Naveen"=>"37", "Amit"=>"43");
echo "Mr.Samy is " . $age['Peter'] . " years old.";
?>
Example 2: array key value php
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
foreach($age as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
Example 3: php variables as keys in arrays
$id = 1;
$age = 2;
$sort = "id";
$Key = $$sort;
$arr = array($Key => 'string');
print_r($arr);