PHP array_push导致脚本停止

I have two arrays, one containing user information and another one containing ids about user from the first array that I don't want to be selected.

I want to insert into a new array data from the first one that are not in the second array.

while ( count( $new_array) < 50 ) 
    {
        $index = array_rand($array_1);

        if ( ! in_array( $array_1[$index]['id'], $array_2) ) 
        {
            array_push( $new_array, $array_1[$index] );
            array_push( $array_2, $array_1[$index]['id'] );
        }
    }

When data are selected from the $array_1 I insert them in $array_2 in order for it not to be selected again. This works if the while loop does not run more than 12 times, but more than that it runs for more than 30 seconds causing the script to stop. What can be the problem?

Instead of attempting to keep track of which index has already been randomly selected from array1, just remove that item from the array after it's been selected. If you need to keep the original array unchanged, start by duplicating it.