Php array fill
From w3cyberlearnings
Contents |
PHP function array_fill
This function creates an array with a specific value, and the array will create with all the same value.
Syntax array_fill
- start: start index
- end: end index
- value: array value for filling
array_fill(start, end, value);
Example 1
<?php $fruit = array_fill(3,5,'apple'); print_r($fruit); ?>
Output
Array ( [3] => apple [4] => apple [5] => apple [6] => apple [7] => apple )
Example 2
<?php $person1 = array('bob', 'janny', 'marry'); $person2 = array_fill(2, 4, 'johnny'); $players = array_merge($person1, $person2); foreach ($players as $person) { echo "{$person} plays for both teamss.<br/>"; } ?>
Output
bob plays for both teamss. janny plays for both teamss. marry plays for both teamss. johnny plays for both teamss. johnny plays for both teamss. johnny plays for both teamss. johnny plays for both teamss.
Related Links
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys