Restore array

Restores the array keys to 0,1,2,3,4,...

function restore_array($arr){
    if (!is_array($arr)){ return $arr; }
    $c = 0; $new = array();
    while (list($key, $value) = each($arr)){
        if (is_array($value)){
            $new[$c] = restore_array($value);
        else { $new[$c] = $value; }
    return $new;
Snippet Details

restore_array(array('a' => 1, 'b' => 2)); --> returns array(0 => 1, 1 => 2)

Sorry folks, comments have been deactivated for now due to the large amount of spam.

Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!

Older comments:

mohsen February 19, 2008 at 02:07