This function deletes the elements of array starting at the position given by offset . If offset is positive, it gives the number of elements from the beginning of array from which to start deleting; if negative, it gives the number of elements from the end at which to start deleting.
array is altered in place, and an array containing the deleted elements is returned.
If length is given and is positive, it gives the number of elements to delete. If negative, it gives the number of elements from the end of array at which to stop deleting. If not given, all elements from offset to the end of array are deleted.
If replacement is given, the deleted elements of array are replaced with the contents of replacement . You can use this to cause replacement to simply be inserted into array with no deletions taking place by setting length to 0.
$arr1 = array("black", "white", "eggplant", "grey"); $arr2 = array("red", "blue", "green"); echo "Original arrays: ", implode(", ", $arr1), " & ", implode(", ", $arr2), "\n"; $items = array_splice($arr1, 1, 2, $arr2); echo "New array: ", implode(", ", $arr1), "\n"; echo "Parts removed: ", implode(", ", $items); Output: Original arrays: black, white, eggplant, grey & red, blue, green New array: black, red, blue, green, grey Parts removed: white, eggplant
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.