Error merging arrays in PHP -
i have nested arrays , want append content of 1 array when keys match. here function instead of appending replacing.
function mergearrays($arr, $ins) { if(is_array($arr)) { if(is_array($ins)) foreach($ins $k=>$v) { if(isset($arr[$k])&&is_array($v)&&is_array($arr[$k])) { $arr[$k] = mergearrays($arr[$k], $v); } else { // new loop :) // while (isset($arr[$k])) // $k++; // here want append instead of add $arr[$k] = $v; } } } else if(!is_array($arr)&&(strlen($arr)==0||$arr==0)) { $arr=$ins; } return($arr); }
any recommendations?
thanks
you can merge entries either adding arrays together, or using array_merge
merge arrays new one.
any reason you're not using array_merge_recursive
solve without custom code?
Comments
Post a Comment