Created
April 10, 2015 08:25
-
-
Save egulhan/35f25e5f27356326fdc2 to your computer and use it in GitHub Desktop.
Function which reindexes arrays for the given object in recursive way
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 characters
| <?php | |
| /** | |
| * Reindexes arrays for the given object in recursive way | |
| * @param $obj | |
| * @return array | |
| */ | |
| function reindex_array_recursive($obj) | |
| { | |
| if(is_array($obj) && !is_array_assoc($obj)) | |
| $obj = array_values($obj); | |
| foreach ($obj as $key => $val) | |
| { | |
| if(is_array($val) || is_object($val)) | |
| { | |
| $ret_val=reindex_array_recursive($val); | |
| if(is_array($obj)) | |
| $obj[$key]=$ret_val; | |
| else | |
| $obj->$key=$ret_val; | |
| } | |
| } | |
| return $obj; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment