Php array_splice function

Source: Internet
Author: User

Array_splice
(PHP 4 and PHP 5)

Array_splice-some arrays are deleted and replaced with others

Description
Array array_splice (array & $ investment, international $ offset [Abstract $ Length = 0 [, mixed $ change])
Delete the specified element offset and length input array, and replace their content to replace the array if provided.

Note that the input number key is not saved.

Note: If the replacement is not an array, it will be a stereotype (that is, the (array) $ parameter ). This may cause unexpected behavior when an object is replaced.

Parameters

Input
Input array.

Offset
If offset is positive then partial offset is removed from the first input array. If offset is negative and then it starts, the input array is far from the bottom.

Length
If the length is omitted, delete all arrays from the end of the offset. If the specified length is positive, many contents will be deleted. If the specified length is negative, the ending part is deleted, and the ending array of many elements is deleted. Tip: remove all replacement arrays from the end of the offset and also specify that the length of the count ($ input) is used.

Change
If you replace the specified array, then the content to be deleted is changed to the array from which the molecules are removed.

If the offset and length are not deleted, the element replaces the specified location offset inserted in the array. Note that the replacement key array is not saved.

If you just replace an element, there is no need to enclose the array () unless the element is an array itself.


Return value
Returns the extracted content composed of arrays.

Instance

Example #1 array_splice ()

<? Php
$ Input = array ("red", "green", "blue", "yellow ");
Array_splice ($ input, 2 );
// $ Input is now array ("red", "green ")

$ Input = array ("red", "green", "blue", "yellow ");
Array_splice ($ input, 1,-1 );
// $ Input is now array ("red", "yellow ")

$ Input = array ("red", "green", "blue", "yellow ");
Array_splice ($ input, 1, count ($ input), "orange ");
// $ Input is now array ("red", "orange ")

$ Input = array ("red", "green", "blue", "yellow ");
Array_splice ($ input,-1, 1, array ("black", "maroon "));
// $ Input is now array ("red", "green ",
// "Blue", "black", "maroon ")

$ Input = array ("red", "green", "blue", "yellow ");
Array_splice ($ input, 3, 0, "purple ");
// $ Input is now array ("red", "green ",
// "Blue", "purple", "yellow ");
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.