PHP Tutorial - PHP array_fill() function fills an array with values






Definition

The array_fill() function fills an array with values.

Syntax

PHP array_fill() function has the following syntax.

array_fill(index,number,value);

Parameter

PHP array_fill() function has the following syntax.

ParameterIs RequiredDescription
indexRequired.The first index
numberRequired.Number of elements to insert
valueRequired.Value to fill the array

Example

Fill an array with values:


<?php
$a1=array_fill(3,4,"java2s.com");
print_r($a1);
?>

The code above generates the following result.