Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

array_fill(3) [php man page]

ARRAY_FILL(3)								 1							     ARRAY_FILL(3)

array_fill - Fill an array with values

SYNOPSIS
array array_fill (int $start_index, int $num, mixed $value) DESCRIPTION
Fills an array with $num entries of the value of the $value parameter, keys starting at the $start_index parameter. PARAMETERS
o $start_index - The first index of the returned array. If $start_index is negative, the first index of the returned array will be $start_index and the following indices will start from zero (see example). o $num - Number of elements to insert. Must be greater than or equal to zero. o $value - Value to use for filling RETURN VALUES
Returns the filled array ERRORS
/EXCEPTIONS Throws a E_WARNING if $num is less than zero. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.6.0 | | | | | | | $num may now be zero. Previously, $num was | | | required to be greater than zero. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 array_fill(3) example <?php $a = array_fill(5, 6, 'banana'); $b = array_fill(-2, 4, 'pear'); print_r($a); print_r($b); ?> The above example will output: Array ( [5] => banana [6] => banana [7] => banana [8] => banana [9] => banana [10] => banana ) Array ( [-2] => pear [0] => pear [1] => pear [2] => pear ) NOTES
See also the Arrays section of manual for a detailed explanation of negative keys. SEE ALSO
array_fill_keys(3), str_repeat(3), range(3). PHP Documentation Group ARRAY_FILL(3)

Check Out this Related Man Page

ARRAY_REPLACE(3)							 1							  ARRAY_REPLACE(3)

array_replace - Replaces elements from passed arrays into the first array

SYNOPSIS
array array_replace (array $array1, array $array2, [array $...]) DESCRIPTION
array_replace(3) replaces the values of $array1 with values having the same keys in each of the following arrays. If a key from the first array exists in the second array, its value will be replaced by the value from the second array. If the key exists in the second array, and not the first, it will be created in the first array. If a key only exists in the first array, it will be left as is. If several arrays are passed for replacement, they will be processed in order, the later arrays overwriting the previous values. array_replace(3) is not recursive : it will replace values in the first array by whatever type is in the second array. PARAMETERS
o $array1 - The array in which elements are replaced. o $array2 - The array from which elements will be extracted. o $... - More arrays from which elements will be extracted. Values from later arrays overwrite the previous values. RETURN VALUES
Returns an array, or NULL if an error occurs. EXAMPLES
Example #1 array_replace(3) example <?php $base = array("orange", "banana", "apple", "raspberry"); $replacements = array(0 => "pineapple", 4 => "cherry"); $replacements2 = array(0 => "grape"); $basket = array_replace($base, $replacements, $replacements2); print_r($basket); ?> The above example will output: Array ( [0] => grape [1] => banana [2] => apple [3] => raspberry [4] => cherry ) SEE ALSO
array_replace_recursive(3), array_merge(3). PHP Documentation Group ARRAY_REPLACE(3)
Man Page