Array_splice acting as array_slice?
I'm having issues understanding exactly what array_splice and array_slice do. From what I can tell array_splice should return an array AFTER taking out certain elements and array_slice should retrieve a slice of the array.

The following code from the [php.net/array_splice][1] manual shows that this code should work.

    $input = array("red", "green", "blue", "yellow");
    var_dump(array_splice($input, 2));
    // $input is now array("red", "green")
    
    $input = array("red", "green", "blue", "yellow");
    var_dump(array_slice($input, 2));
    // $input is now array("red", "green")

However when I run this code on php 5.3.4 and 5.1.6 the results are

    array
      0 => string 'blue' (length=4)
      1 => string 'yellow' (length=6)
    array
      0 => string 'blue' (length=4)
      1 => string 'yellow' (length=6)

Am I misunderstanding the manual or is this a bug? It looks to me like array_splice is acting just like array_slice

Also it does not seem to do replacements

    $input = array("red", "green", "blue", "yellow");
    var_dump(array_splice($input, 2, 2, array('foo')));

outputs

    array
      0 => string 'blue' (length=4)
      1 => string 'yellow' (length=6)


  [1]: http://php.net/array_splice

Can someone confirm this is a bug and if not explain how this SHOULD work?


EDIT:

Nvm I figured it out. Instead of using a var_dump on the array_splice I should be using $input as array_splice changes $input instead of returning the new values.

MODs please close or delete this.
Array_splice acting as array_slice?
===

I'm having issues understanding exactly what array_splice and array_slice do. From what I can tell array_splice should return an array AFTER taking out certain elements and array_slice should retrieve a slice of the array.

The following code from the [php.net/array_splice][1] manual shows that this code should work.

    $input = array("red", "green", "blue", "yellow");
    var_dump(array_splice($input, 2));
    // $input is now array("red", "green")
    
    $input = array("red", "green", "blue", "yellow");
    var_dump(array_slice($input, 2));
    // $input is now array("red", "green")

However when I run this code on php 5.3.4 and 5.1.6 the results are

    array
      0 => string 'blue' (length=4)
      1 => string 'yellow' (length=6)
    array
      0 => string 'blue' (length=4)
      1 => string 'yellow' (length=6)

Am I misunderstanding the manual or is this a bug? It looks to me like array_splice is acting just like array_slice

Also it does not seem to do replacements

    $input = array("red", "green", "blue", "yellow");
    var_dump(array_splice($input, 2, 2, array('foo')));

outputs

    array
      0 => string 'blue' (length=4)
      1 => string 'yellow' (length=6)


  [1]: http://php.net/array_splice

Can someone confirm this is a bug and if not explain how this SHOULD work?


EDIT:

Nvm I figured it out. Instead of using a var_dump on the array_splice I should be using $input as array_splice changes $input instead of returning the new values.

MODs please close or delete this.