PHP allows you to extract a subsection of the array with the array_slice() function, in much the same way that the substr() function allows you to extract a section of a string. Here's what it looks like: where "array" is an array variable, "start" is the index to begin slicing at, and "length" is the number of elements to return from "start". Here's an example: You can also use a negative index for the "start" position, to force PHP to begin counting from the right instead of the left. The array_splice() function allows you to splice one or more values into an existing array. Here's what it looks like: where "array" is an array variable, "start" is the index to begin slicing at, "length" is the number of elements to return from "start", and "replacement-values" are the values to splice in. Here's an example:
blog comments powered by Disqus |