What is a two-dimensional php array? Php two-dimensional array example

Source: Internet
Author: User
A two-dimensional array is also called a matrix. in essence, an array is used as an array of array elements. If an array element is a one-dimensional array, this array is called a two-dimensional array. What is a two-dimensional php array?

A two-dimensional array is also called a matrix. in essence, an array is used as an array of array elements. If an array element is a one-dimensional array, this array is called a two-dimensional array.

PHP two-dimensional array example

In our previous article "PHP array type-multi-dimensional array", we explained two-dimensional arrays. text descriptions may make everyone more confused and intuitive without code examples, the following is an example to show you at a glance!

PHP two-dimensional array code example:

 Array ("PHP", "Chinese", "net"), "Sporting Goods" => array ("M" => "football ", "N" => "Basketball"), "fruit" => array ("Orange", 8 => "grape", "Apple ")); // declare the array print_r ($ ASD); // Print the output array?>

Output result:

Array ([website] => Array ([0] => PHP [1] => Chinese [2] => Network) [Sporting Goods] => Array ([M] => Football [N] => Basketball) [fruit] => Array ([0] => Orange [8] => Grape [9] => Apple ))

It is described as follows:

Many people see why the following table for "Apple" is "9?

We have mentioned in previous articles that the array subscript starts from 0 by default and increases by 1 in turn. of course, you can also specify a number to start, because we previously defined "grape" as 8, the subscript of "apple" is 9. What do you understand now?

The above example implements the declaration of a two-dimensional array. in this way, we can declare an array with a higher dimension. isn't it easy, refer to our previous article "PHP array type-multi-dimensional array"!

[Recommended tutorials]

1. related topic recommendations: php Array (Array)

What is the above two-dimensional php array? For more details about php two-dimensional array instances, see other related articles in the first PHP community!

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.