Jump to: navigation, search

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


Navigation
Web
SQL
MISC
References