I have 2 arrays.
$result = array();
$row = array();
Row\'s elements are all references and is constantly changing. For each iteration of
Not sure I totally understand the question, but can you use recursion?
function array_copy($source) {
$arr = array();
foreach ($source as $element) {
if (is_array($element)) {
$arr[] = array_copy($element);
} else {
$arr[] = $element;
}
}
return $arr;
}
$result = array();
$row = array(
array('a', 'b', 'c'),
array('d', 'e', 'f')
);
$result[] = array_copy($row);
$row[0][1] = 'x';
var_dump($result);
var_dump($row);
Extending the function above like follows solved a problem I had:
function array_copy($source) {
$arr = array();
foreach ($source as $element) {
if (is_array($element)) {
$arr[] = array_copy($element);
} elseif (is_object($element)) {
// make an object copy
$arr[] = clone $element;
} else {
$arr[] = $element;
}
}
return $arr;
}
$result = array_map(function($_){return $_;}, $row);