Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write two-dimensional array in php

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shows you how to write a two-dimensional array in php, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Php two-dimensional array to write: 1, direct assignment method, syntax "$array [one-dimensional subscript] [two-dimensional subscript] =" value "; 2, the use of array () function, syntax" array (key= > value...), array (key= > value...).

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Two-dimensional array

A two-dimensional array is declared in the same way as an one-dimensional array, except that one or more elements in the array are also declared as an array. There are also two ways to declare a two-dimensional array by directly assigning values to the array elements and using the array () function.

Let's declare an array by assigning values to array elements directly. The sample code is as follows:

The running results are as follows:

Array ([0] = > Array ([name] = > zhangsan [chinese] = > 89 [math] = > 95 [english] = > 88) [1] = > Array ([name] = > lisi [chinese] = > 91 [math] = > 86 [english] = > 90))

Using the array () function to declare a two-dimensional array is similar to declaring an one-dimensional array. The sample code is as follows: (the following is equivalent to the above code, and the running result is the same)

Similarly, getting the elements in a two-dimensional array is similar to an one-dimensional array, only need to indicate the subscript of each dimension. The example code is as follows:

The running results are as follows:

Zhangsan got 95 points in math.

Tip: different dimensions of the array indicate that we need to use several subscripts (indexes) to get the corresponding array elements, such as two subscripts for a two-dimensional array, three for a three-dimensional array, and so on.

The above is how to write a two-dimensional array in php. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report