array_fill() function in PHP


The array_fill() function is used to fill an array with values. It returns the filled array. It returns the filled array.

Syntax

array_fill(start_index, num, value)

Parameters

  • start_index − First index of the returned array. Required.

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

  • value − The value that would fill the array. Required.

Return

The array_fill() function returns the filled array.

Example

Live Demo

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

Output

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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

113 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements