How to define multi-dimensional arrays with array_fill function in PHP

墨辰丷
Release: 2023-03-31 18:30:01
Original
1653 people have browsed it

This article mainly introduces the method of using array_fill in PHP to define multi-dimensional arrays. The example analyzes the usage skills of the array_fill function in PHP. It has certain reference value. Friends who need it can refer to it

The examples in this article are described PHP uses array_fill to define multi-dimensional arrays. The specific analysis is as follows:

Multiple array_fill nestings can be used in PHP to complete the definition of multi-dimensional arrays:

$creation=array_fill(0,3,array_fill(0,2,null));
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

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

php implements syntax highlighting through regular expressions

php operates text files to delete duplicate lines

PHP implements refresh-free login and exit based on Ajax

PHP implements city switching or jump based on IP

PHP implements refresh-free login and exit based on Ajax

The above is the detailed content of How to define multi-dimensional arrays with array_fill function in PHP. For more information, please follow other related articles on the PHP Chinese website!

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
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!