Skip to content

Instantly share code, notes, and snippets.

@spolischook
Created May 21, 2013 17:16
Show Gist options
  • Save spolischook/5621504 to your computer and use it in GitHub Desktop.
Save spolischook/5621504 to your computer and use it in GitHub Desktop.
<?php
$array = array(
0 => 0,
1 => 1,
2 => 2,
3 => array(
0 => 30,
1 => 31,
2 => 32,
3 => 33,
4 => 34,
),
4 => 4,
5 => 5,
);
$obj = new ArrayObject($array);
function updateArray($obj) {
$iterator = $obj->getIterator();
while($iterator->valid()) {
if (is_array($iterator->current())) {
$obj->offsetSet(
$iterator->key(),
new ArrayObject($iterator->current()))
;
updateArray($obj->offsetGet($iterator->key()));
} else {
$obj->offsetSet(
$iterator->key(),
$obj->offsetGet($iterator->key()) + 100)
;
}
$iterator->next();
}
}
updateArray($obj);
var_dump($obj);
/*
Output
object(ArrayObject)[1]
int 100
int 101
int 102
object(ArrayObject)[3]
int 130
int 131
int 132
int 133
int 134
int 104
int 105
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment