Hello all.

I need an alternative to array_shift.

I have an array used for a search engine. The key's are the literal ID of the match, and the value is the match's score.

When you use array_shift, returned results key's are reset to 0 and increment from there, while the value remains intact.

I've tried to use a for and unset the array, but it's no good due to the key's not being in sequential order.

example of array

Array
(
    [33] => 20502
    [35] => 20453
    [34] => 20401
    [28] => 20203
    [24] => 20202
    [83] => 20201
    [1227] => 20101
    [709] => 20052
    [25] => 20051
    [750] => 20050
    [1905] => 20003
    [1789] => 20001
    [1287] => 10101
    [1185] => 10100
    [297] => 10050
    [230] => 10001
)

TIA.

    Have you tried "foreach"?

    foreach ($array as $key => $value) {
        echo $key . ' => ' . $value . '<br />';
        unset($array[$key]);
    }

      Got it working.

      I had tried foreach before, but I could never get it to work, I didnt know that you could call reference to the $array in $array as $key=>$val

      Thanks!

      $nskip = 10; //example to skip
      $i = 0; //first key is always 0
                foreach($results as $key => $val){
                    if($i < $nskip) 
                      unset($results[$key]);
                    $i++;
                }
        Write a Reply...