note 34380 modified in function.array-merge by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 13:59:00 +0000 |
| Subject: | note 34380 modified in function.array-merge by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79840@lists.php.net to get a copy of this message | ||
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;
}
?>
--was--
This function merges any number of arrays and maintains the keys:
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;
}
http://php.net/manual/en/function.array-merge.php