Php outputs two-dimensional array

Source: Internet
Author: User
Tags arrays

2d array access
Example 1:

The code is as follows: Copy code
// Create an array
$ Arr = array ("key" => array ("key2" => "value "));
// Access the "key2" element of the two-dimensional array
Echo $ arr ["key"] ["key2"];
Example 2:
// Create an array
$ Arr = array ("key2" => "value "));
// Access the "key2" element of the two-dimensional array
Echo $ arr [0] ["key2"];

Multi-dimensional arrays, and so on
$ Arr ["key value"] ["key value"] ["key value"] ["key value"] ["key value"]...

Instance:

The code is as follows: Copy code
$ Myphonebook = array (
Array ("abcd", "1234 "),
Array ("efgh", "5678 "),
Array ("ijkl", "9012 ")
);
Echo $ myphonebook [0] [0]; // abcd
Echo $ myphonebook [0] [1]; // 1234


Read two-dimensional arrays cyclically

 

The code is as follows: Copy code
While ($ row = $ db-> fetch_array ($ query )){
$ Arr [] = array ($ row [id], $ row [f_id], $ row [name]);
// $ Arr [] = array ('id' => $ row [id], 'F _ id' => $ row [f_id], 'name' => $ row [name]);
}

Another way to read two-dimensional arrays is to use foreach () for operations. I will not talk about it here. I have previously written related articles and can search for them if necessary.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.