PHP array_fill() function

P
PHP array_diff_ukey() function
PHP array_fill_keys() function

The array_fill function simply fills an array with the provided values. This function is useful especially when we need to initialize an array with some dummy data.

What is the syntax of the array_fill function in PHP?

array_fill(index, number, value)
ParametersDetails
indexIndex of the array to start inserting the value at – required
numberSpecify the number of elements to insert – required
valueSpecify the value to insert – required
array_fill function in PHP

Example of array_fill function

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

In the above example, the array_fill function returns an array containing “blue” at the index numbers 3, 4, 5, and 6. This is because we specified the string to start appearing at index 3 and repeat four times.

PHP array_diff_ukey() function
PHP array_fill_keys() function

Add comment

Tutor Network

Share this

Learn PHP from A to Z