make value as key in array php code example
Example 1: 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 2: php variables as keys in arrays
$id = 1;
$age = 2;
$sort = "id"; // or "age";
$Key = $$sort;
$arr = array($Key => 'string');
print_r($arr);