PHP array_fill() function
In this chapter you will learn:
- Definition for PHP array_fill() function
- Syntax for PHP array_fill() function
- Parameter for PHP array_fill() function
- Example - Fill 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.
Parameter | Is Required | Description |
---|---|---|
index | Required. | The first index |
number | Required. | Number of elements to insert |
value | Required. | 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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP array_fill_keys() function
- Syntax for PHP array_fill_keys() function
- Parameter for PHP array_fill_keys() function
- Example - Fill an array with values, specifying keys
Home » PHP Tutorial » PHP Array Functions