Home >Backend Development >PHP Tutorial >In PHP, the array_fill() function is used to fill an array with a specified value.

In PHP, the array_fill() function is used to fill an array with a specified value.

王林
王林forward
2023-08-19 22:37:451409browse

In PHP, the array_fill() function is used to fill an array with a specified value.

array_fill() function is used to fill the values ​​of the array. It returns the populated array. It returns the populated array.

grammar

array_fill(start_index, num, value)

parameter

  • start_index − Returns the first index of the array. Required.

  • num − The number of elements to insert. Required.

  • value − The value to fill the array. Required.

return

array_fill() function returns the filled array.

The Chinese translation of

Example

is:

Example

Real-time demonstration

<?php
   $a = array_fill(3, 5, 'demo');
   print_r($a);
?>

Output

Array (
   [3] => demo
   [4] => demo
   [5] => demo
   [6] => demo
   [7] => demo
)

The above is the detailed content of In PHP, the array_fill() function is used to fill an array with a specified value.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete