Home > Backend Development > PHP Tutorial > How to use array_fill function in php

How to use array_fill function in php

藏色散人
Release: 2023-04-06 19:38:01
Original
3539 people have browsed it

Usage of array_fill function in php: [array_fill(index,number,value)]. The array_fill function is used to fill the given key value into an array and return the filled array.

How to use array_fill function in php

php The array_fill function is to fill the array with key values. Its syntax is array_fill(index,number,value). The parameter index is required and is the returned array. The first index; number is required and specifies the number of elements to be inserted; value is required and specifies the value used to fill the array.

(Recommended tutorial: php video tutorial)

How to use the php array_fill function?

Function: Fill the array with key values.

Syntax:

array_fill(index,number,value)
Copy after login

Parameters:

index Required. The first index of the returned array.

number Required. Specifies the number of elements to insert.

value Required. Specifies the values ​​used to populate the array.

Description:

Fill the array with the given value. The returned array has number elements and the value is value. The returned array is numerically indexed, starting at the start position and increasing. If number is 0 or less than 0, an error occurs.

php array_fill() function usage example 1

<?php
$a=array_fill(2,3,"无忌");
print_r($a);
?>
Copy after login

Output:

Array ( [2] => 无忌 [3] => 无忌 [4] => 无忌 )
Copy after login

php array_fill() function usage example 2

<?php
$a=array_fill(1,2,"西门");
print_r($a);
?>
Copy after login

Output:

Array ( [1] => 西门 [2] => 西门 )
Copy after login

The above is the detailed content of How to use array_fill function in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template