Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

array_pad(3) [php man page]

ARRAY_PAD(3)								 1							      ARRAY_PAD(3)

array_pad - Pad array to the specified length with a value

SYNOPSIS
array array_pad (array $array, int $size, mixed $value) DESCRIPTION
array_pad(3) returns a copy of the $array padded to size specified by $size with value $value. If $size is positive then the array is padded on the right, if it's negative then on the left. If the absolute value of $size is less than or equal to the length of the $array then no padding takes place. It is possible to add at most 1048576 elements at a time. PARAMETERS
o $array - Initial array of values to pad. o $size - New size of the array. o $value - Value to pad if $array is less than $size. RETURN VALUES
Returns a copy of the $array padded to size specified by $size with value $value. If $size is positive then the array is padded on the right, if it's negative then on the left. If the absolute value of $size is less than or equal to the length of the $array then no padding takes place. EXAMPLES
Example #1 array_pad(3) example <?php $input = array(12, 10, 9); $result = array_pad($input, 5, 0); // result is array(12, 10, 9, 0, 0) $result = array_pad($input, -7, -1); // result is array(-1, -1, -1, -1, 12, 10, 9) $result = array_pad($input, 2, "noop"); // not padded ?> SEE ALSO
array_fill(3), range(3). PHP Documentation Group ARRAY_PAD(3)

Check Out this Related Man Page

ARRAY_SPLICE(3) 							 1							   ARRAY_SPLICE(3)

array_splice - Remove a portion of the array and replace it with something else

SYNOPSIS
array array_splice (array &$input, int $offset, [int $length], [mixed $replacement = array()]) DESCRIPTION
Removes the elements designated by $offset and $length from the $input array, and replaces them with the elements of the $replacement array, if supplied. Note that numeric keys in $input are not preserved. Note If $replacement is not an array, it will be typecast to one (i.e. (array) $parameter). This may result in unexpected behavior when using an object or NULL$replacement. PARAMETERS
o $input - The input array. o $offset - If $offset is positive then the start of removed portion is at that offset from the beginning of the $input array. If $offset is negative then it starts that far from the end of the $input array. o $length - If $length is omitted, removes everything from $offset to the end of the array. If $length is specified and is positive, then that many elements will be removed. If $length is specified and is negative then the end of the removed portion will be that many elements from the end of the array. If $length is specified and is zero, no elements will be removed. Tip: to remove everything from $offset to the end of the array when $replacement is also specified, use count($input) for $length. o $replacement - If $replacement array is specified, then the removed elements are replaced with elements from this array. If $offset and $length are such that nothing is removed, then the elements from the $replacement array are inserted in the place specified by the $offset. Note that keys in replacement array are not preserved. If $replacement is just one element it is not necessary to put array() around it, unless the element is an array itself, an object or NULL. RETURN VALUES
Returns the array consisting of the extracted elements. EXAMPLES
Example #1 array_splice(3) examples <?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"); ?> Example #2 array_splice(3) examples The following statements change the values of $input the same way: <?php array_push($input, $x, $y); array_splice($input, count($input), 0, array($x, $y)); array_pop($input); array_splice($input, -1); array_shift($input); array_splice($input, 0, 1); array_unshift($input, $x, $y); array_splice($input, 0, 0, array($x, $y)); $input[$x] = $y; // for arrays where key equals offset array_splice($input, $x, 1, $y); ?> SEE ALSO
array_slice(3), unset(3), array_merge(3). PHP Documentation Group ARRAY_SPLICE(3)
Man Page