note 101134 added to function.array-replace
| From: | polecat at p0lecat dot com | Date: | Sun, 28 Nov 2010 22:53:29 +0000 |
| Subject: | note 101134 added to function.array-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174425@lists.php.net to get a copy of this message | ||
With PHP 5.3 still unstable for Debian Lenny at this time and not knowing if array_replace would
work with multi-dimensional arrays, I wrote my own. Since this site has helped me so much, I felt
the need to return the favor. :)
// Polecat's Multi-dimensional array_replace function
// Will take all data in second array and apply to first array leaving any non-corresponding
values untouched and intact
function polecat_array_replace( array &$array1, array &$array2 ) {
// This sub function is the iterator that will loop back on itself ad infinitum till it runs out
of array dimensions
function tier_parse(array &$t_array1, array&$t_array2) {
foreach ($t_array2 as $k2 => $v2) {
if (is_array($t_array2[$k2])) {
tier_parse($t_array1[$k2], $t_array2[$k2]);
} else {
$t_array1[$k2] = $t_array2[$k2];
}
}
return $t_array1;
}
foreach ($array2 as $key => $val) {
if (is_array($array2[$key])) {
tier_parse($array1[$key], $array2[$key]);
} else {
$array1[$key] = $array2[$key];
}
}
return $array1;
}
----
Server IP: 69.147.83.197
Probable Submitter: 70.241.103.180
----
Manual Page -- http://www.php.net/manual/en/function.array-replace.php
Edit -- https://master.php.net/note/edit/101134
Del: integrated -- https://master.php.net/note/delete/101134/integrated
Del: useless -- https://master.php.net/note/delete/101134/useless
Del: bad code -- https://master.php.net/note/delete/101134/bad+code
Del: spam -- https://master.php.net/note/delete/101134/spam
Del: non-english -- https://master.php.net/note/delete/101134/non-english
Del: in docs -- https://master.php.net/note/delete/101134/in+docs
Del: other reasons-- https://master.php.net/note/delete/101134
Reject -- https://master.php.net/note/reject/101134
Search -- https://master.php.net/manage/user-notes.php