Definition and Usage
The Array_slice () function takes a value out of the array and returns it as a condition.
Note: If the array has a string key, the returned array retains the key name. (see Example 4)
Grammar
Array_slice (Array,start,length,preserve)
Parameter description
Array must be. Specifies the array.
Start must have. Numerical. Specifies the starting position of the element to be removed. 0 = first element.
If the value is set to a positive number, it is taken from the previous start.
If the value is set to a negative number, the start absolute value is taken from the back forward. 2 means starting with the second-to-last element of the array.
length Optional. Numerical. Specifies the length of the returned array.
If the value is set to an integer, the number of elements is returned.
If the value is set to a negative number, the function terminates the fetch at such a distance from the end of the example array.
If the value is not set, returns all elements starting at the position set by the start parameter until the end of the array.
Preserve Optional. Specifies whether the function retains the key name or resets the key name. Possible values:
True-reserved Key name
False-Default. Reset Key Name
return Value: returns the selected part of the array.
Example 1:
<! DOCTYPE Html>
Operation Result:
Array ([0] = green [1] = blue)
Example 2:
Use the negative start parameter:
<! DOCTYPE Html>
Operation Result:
Array ([0] = yellow)
Example 3:
Set the Preserve parameter to true:
<! DOCTYPE Html>
Operation Result:
Array ([1] = green [2] = blue)