Anon;10119397 wrote:The problem:
$arrayOne[] = "bla one";
$arrayOne[] = "bla two";
$arrayOne[] = "bla three";
$arrayOne[] = "junk";
$arrayOne[] = "bla five";
$arrayTwo[] = "zaa four";
// array_splice -- Remove a portion of the array and replace it
// with something else
// array array_splice (array input, int offset [, int length [, array replacement]])
$perfectArray = array_splice($arrayOne, 3, 1, $arrayTwo);
I would expect $perfectArray to be:
$perfectArray[0] = "bla one";
$perfectArray[1] = "bla two";
$perfectArray[2] = "bla three";
$perfectArray[3] = "zaa four";
$perfectArray[4] = "bla five";
But instead I get:
$perfectArray[0] = "junk";
This is what I would expect from array_slice not array_splice. This in PHP4.03. I've have a work around but these seems a little freaky... does anyone else encounter this and if so what version of PHP? Anyone know whare to post bugs?
Dee
Hi Anon,
I got the same problem in my PHP 5.2.5 (cli) (built: Nov 8 2007 23:18:51).
php -r "$input=array('red','green','blue','yellow'); print_r(array_splice($input,2));"
It was suppose to give output array("red", "green")
instead it gives me
Array
(
[0] => blue
[1] => yellow
)
php -r "$input=array('red','green','blue','yellow'); print_r(array_splice($input,2,1));"
suppose to output Array('red','green','yellow');
but it gives Array ( [0] => blue )
I found array_splice is behaving same like array_slice in my php 🙁
If anyone has any solution without changing the version of php please let me know, or post this bug.