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

黄舟
Release: 2023-03-17 07:36:01
Original
1242 people have browsed it

Example

Fill the array with the given key value:

Copy after login

Definition and usage

array_fill() function fills the array with the given key value.

Syntax

array_fill(index,number,value);
Copy after login
Parameters Description
index Required. Specifies the starting index of the returned array.
number Required. Specifies the number of elements to fill. Its value must be greater than 0.
value Required. Specifies the key values used to populate the array.

Technical Details

Return value: Returns the populated array.
PHP Version: 4.2+

Example

Copy after login

Output:

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

can be filled with the following statements:

$abc=0; for($i=0;$i<3;$i++) { for($j=0;$j<2;$j++) { $abc=$abc+1; $creation[$i][$j]=$abc; } }
Copy after login

The result is:

Array ( [0] => Array ( [0] => 1 [1] => 2 ) [1] => Array ( [0] => 3 [1] => 4 ) [2] => Array ( [0] => 5 [1] => 6 ) )
Copy after login

The above is the detailed content of PHP function array_fill() that fills an array with a given key value. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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 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!