Created
June 25, 2012 17:19
Revisions
-
mlconnor revised this gist
Jun 25, 2012 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,8 +14,9 @@ function walk_recursive($obj, $closure) { return $newObj; } else if ( is_array($obj) ) { $newArray = array(); foreach ($obj as $key => $value) { $key = $closure($key); $newArray[$key] = walk_recursive($value, $closure); } return $newArray; } else { -
mlconnor created this gist
Jun 25, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ /** * works for json objects. will replace all * keys and values with the result of the * closure. */ function walk_recursive($obj, $closure) { if ( is_object($obj) ) { $newObj = new stdClass(); foreach ($obj as $property => $value) { $newProperty = $closure($property); $newValue = walk_recursive($value, $closure); $newObj->$newProperty = $newValue; } return $newObj; } else if ( is_array($obj) ) { $newArray = array(); foreach ($obj as $value) { $newArray[] = walk_recursive($value, $closure); } return $newArray; } else { return $closure($obj); } }