English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_fill() Function Usage and Example

PHP Array Function Manual

The PHP array_fill() function fills an array with a given value

Syntax

array array_fill( int start_index, int num, mixed value );

Definition and Usage

  • start_index
    The first index value of the returned array.
    If start_index is negative, the first index of the returned array will be start_index, and the subsequent indices will start from 0. (See Example).

  • num
    The number of elements to insert. Must be greater than or equal to 0.

  • value
    The value to be filled in.

Parameter

NumberParameters and Description
1

start_index

Returns the first index of the array

2

num

It contains the number of elements to insert

3

value

It contains the values used to fill

Return Value

It returns an array filled with values

Online Example

<?php
   $input = array_fill(5, 6, 'apple');
   print_r($input);
?>
Test and See ‹/›

Output Result:

Array (
   [5] => apple
   [6] => apple
   [7] => apple
   [8] => apple
   [9] => apple
   [10] => apple
)

 PHP Array Function Manual