RE: [PHP] Array_splice vs. array_slice

From: Date: Fri, 18 Oct 2002 13:51:35 +0000
Subject: RE: [PHP] Array_splice vs. array_slice
Groups: php.general 
Request: Send a blank email to php-general+get-120505@lists.php.net to get a copy of this message
Hi Liam, > If I have: > $arrayvalues = { "1", "2", "3", "4", "5" }; > Both array_spilce($arrayvalues, 2, 1) and > array_slice($arrayvalues, 2, 1) seem to return only 3. That's right. array_slice($arrayvalues, 2, 1) returns 1 element starting from index 2 (i.e. "3"). It doesn't remove the element, just return it. array_splice($arrayvalues, 2, 1) removes this element and replaces it with nothing (you didn't specify a replacement array). As per the manual description, it returns the elements it has removed (i.e. "3"). If you try array_splice($arrayvalues, 2, 1, array("6")), then you should see a difference to $arrayvalues, but your array_splice call will still return 3. Cheers Jon

« previous php.general (#120505) next »