note 34380 deleted from function.array-merge by salathe
| From: | salathe@php.net | Date: | Mon, 06 Sep 2021 22:46:21 +0000 |
| Subject: | note 34380 deleted from function.array-merge by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216900@lists.php.net to get a copy of this message | ||
Note Submitter: tobias_mik at hotmail dot com
----
This function merges any number of arrays and maintains the keys:
<?php
function array_kmerge ($array) {
reset($array);
while ($tmp = each($array))
{
if(count($tmp['value']) > 0)
{
$k[$tmp['key']] = array_keys($tmp['value']);
$v[$tmp['key']] = array_values($tmp['value']);
}
}
while($tmp = each($k))
{
for ($i = $start; $i < $start+count($tmp['value']); $i
++)$r[$tmp['value'][$i-$start]] = $v[$tmp['key']][$i-$start];
$start = count($tmp['value']);
}
return $r;
}
?>