PHP interesse |
|
Martijn schreef: je kunt met een foreach door array1 lopen (als die de meeste keys heeft), en dan steeds
if isset ($array2[$key]) { $array1[$key] = array($value,$array2[$key]);
Heb geprobeerd maar helaas!
De volgende code bracht de oplossing:
function array_merge_keys($ray1, $ray2)
{
$retval = array();
$keys = array_unique(array_merge(array_keys($ray1),array_keys($ray2)));
foreach ($keys as $item)
{
$retval[$item] = array();
foreach ($ray1[$item] as $aaa => $bbb)
{
$retval[$item][$aaa] = $bbb;
}
foreach ($ray2[$item] as $aaa => $bbb)
{
$retval[$item][$aaa] = $bbb;
}
}
return $retval;
}
$records = array_merge_keys($identifiers, $aVeld);
function array_merge_keys($ray1, $ray2) { foreach ($keys as $item) { $retval[$item] = array(); foreach ($ray1[$item] as $aaa => $bbb) { $retval[$item][$aaa] = $bbb; } foreach ($ray2[$item] as $aaa => $bbb) { $retval[$item][$aaa] = $bbb; } } return $retval; } $records = array_merge_keys($identifiers, $aVeld);
|