Home > Backend Development > PHP Problem > Learn more about PHP arrays! ! !

Learn more about PHP arrays! ! !

慕斯
Release: 2023-03-10 06:20:02
Original
1646 people have browsed it

The previous article introduced you to "How to process PHP forms? If it were you, how would you handle it? 》, this article continues to introduce PHP multi-dimensional arrays to you. I believe many friends have some confusion about arrays. What are you waiting for? Let’s go together! ! !

Learn more about PHP arrays! ! !

What is PHP multidimensional array:

Multidimensional array, each element consists of a value and multiple elements that can be determined The position is composed of subscripts. According to the description of the order relationship of multiple subscript changes in the array, the predecessor and successor relationships of the array elements can be determined and the corresponding linear table can be written.

Multi-dimensional arrays can also be composed of elements (n 1) It is defined by a special linear table of dimensional arrays, so that multi-dimensional arrays with dimensions greater than one are synthesized by the linear table structure, which is a generalization of linear tables.

As shown in the picture below:

Learn more about PHP arrays! ! !

Regarding PHP multi-dimensional arrays, we take the specific code as an example:

<?php
// 二维数组:
$cars = array
(
    array("YSL",200,90),
    array("TF",80,59),
    array("cpb",350,100)
);
print_r($cars); 
?>
Copy after login

The running results are as follows Display:

Learn more about PHP arrays! ! !PHP - Multidimensional Array

A multidimensional array is an array that contains one or more arrays.

In a multi-dimensional array, each element in the main array can also be an array, and each element in the sub-array can also be an array.

The code is shown as follows:

<?php 
$sites = array 
( 
    "php"=>array 
    ( 
        "php中文网", 
        "http://www.php.cn" 
    ), 
    "google"=>array 
    ( 
        "拼多多", 
        "http://www.pingduoduo.com" 
    ), 
    "taobao"=>array 
    ( 
        "京东", 
        "http://www.jingdong.com" 
    ) 
); 
print("<pre class="brush:php;toolbar:false">"); // 格式化输出数组 
print_r($sites); 
print("
Copy after login
"); ?>

The running results are as follows:

Learn more about PHP arrays! ! !

Recommended learning: "PHP Video Tutorial

The above is the detailed content of Learn more about PHP arrays! ! !. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template