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.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions