Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to reindex array in php?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 719
    Comment on it

    Hello Readers!, If you have an array whose key index are missing then you could use the 'array_values' function to easily reindex the array. Let's see the example below:-

     <?php
    
        $array = array( 0 => 'string1', 2 => 'string2', 4 => 'string3', 5 => 'string4');
        $arrays =$array;
        print_r($array);
    echo "<br> now the reindex array <br>";
        $myArray  = array_values($arrays);
        print_r($myArray);
        ?>
    

    Output:-

     Array
        (
            [0] => string1
            [2] => string2
            [4] => string3
            [5] => string4
        )
     now the reindex array
        Array
        (
            [0] => string1
            [1] => string2
            [2] => string3
            [3] => string4
        )
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: