I want to create a new array, and set its keys equal to the values of another array.
Start:
$names = array("don","james","jennifer","paul");
$ages = array("don" => 25, "paul" => 32);
Finish:
$name_age_map = array(
"don" => 25,
"james" => null,
"jennifer" => null,
"paul" => 32,
);
How should this be done in PHP? This is the best I've got so far:
$name_age_map = array();
foreach ($names as $name) {
$name_age_map[$name] = $name_map[$name];
}
Ideally I wouldn't even create a new array, I'd just give element in $names a value of the age.