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

王林
Release: 2023-08-19 22:40:01
forward
1386 people have browsed it

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)
Copy after login

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);
?>
Copy after login

Output

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

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!