Skip to content

Instantly share code, notes, and snippets.

@egulhan
Created April 10, 2015 08:25
Show Gist options
  • Select an option

  • Save egulhan/35f25e5f27356326fdc2 to your computer and use it in GitHub Desktop.

Select an option

Save egulhan/35f25e5f27356326fdc2 to your computer and use it in GitHub Desktop.
Function which reindexes arrays for the given object in recursive way
<?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