This may come as a bit of a shock to you, but PHP's arrayfunctions can do a lot more than just count the elements of an array oriterate through key-value pairs. This article takes an in-depth look atPHP's less well-known array manipulation tools, illustrating how they canbe used to write tighter, more efficient code...and have some fun in thebargain as well!
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:
array_slice(array, start, length)
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".
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:
<?
// create array
$trio = array("huey", "dewey", "louie");
// section to be spliced in
$splice = array("larry", "curly", "moe");
// $trio now contains ("huey", "larry", "curly", "moe")
array_splice($trio, 1, 2, $splice);
?>