set new key value in array php code example
Example 1: insert key-value pair into array php
// If you are creating new array then try this :
$arr = array("key" => "value");
// And if array is already created then try this :
$arr["key"] = "value";
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);