Deep Array Reverse

Recursively reverses a multi-depth array.

function deep_array_reverse($data)
{
        $output = array();
  $keys = array_keys($data);
  for ($i=count($data)-1; $i>=0; $i--)
  {
    if (is_array($data[$keys[$i]]))
    {
      $output[$keys[$i]] = deep_array_reverse($data[$keys[$i]]);
    }
    else
    {
      $output[$keys[$i]] = $data[$keys[$i]];
    }
 }
 return $output;
}

Reply

  • Allowed HTML tags: <b> <br> <p> <a> <strong> <cite> <em> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You may use [img:xx] tags to display uploaded files or images inline.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <css>, <diff>, <drupal5>, <html>, <javascript>, <php>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options