
Originally Posted by
sheep92342
Returning the arrays are ok, it's just adding a new element to the end arrays.
That's why I suggested you return it by reference.
PHP Code:
function & get_node_by_coordinates(&$tree, $coord0, $coord1) {
if ($tree[0] === $coord0 && $tree[1] === $coord1) {
return $tree;
}
if (isset($tree[3])) {
$node =& get_node_by_coordinates($tree[3], $coord0, $coord1);
if ($node) {
return $node;
}
}
if (isset($tree[4])) {
$node =& get_node_by_coordinates($tree[4], $coord0, $coord1);
if ($node) {
return $node;
}
}
return false;
}
PHP Code:
$mn_node =& get_node_by_coordinates($tree, 'm', 'n');
print_r($mn_node);
$mn_node[3] = 'hi!'; // add a new array(node) here
print_r($tree);
Bookmarks