What is a PHP two-dimensional array? PHP two-dimensional array instance detailed

Source: Internet
Author: User
What is a PHP two-dimensional array?

A two-dimensional array, also known as a matrix, is essentially an array of array elements, an array of elements if it is a one-dimensional array, then we call this array a two-dimensional array.

PHP Two-dimensional array instance detailed

One of our previous article, "type of PHP array-multidimensional array," there are two-dimensional array, the text description may make everyone more confused, no code example to the intuitive, below we specific examples to let everyone at a glance!

PHP Two-dimensional array code example:

<?phpheader ("content-type:text/html; Charset=utf-8 "); $atr = Array ("    Web "=>array (" PHP "," Chinese "," net "),    " Sporting Goods "=>array (" M "=" Football "," N "=" basketball " ),    "Fruit" =>array ("orange",8=> "Grape", "apple");               Declares an array of print_r ($ATR);  Print output Array?>

The output is:

Array ([site] = = Array ([0] = php[1] = Chinese [2] = net) [Sporting goods] = = Array ([M] = = Soccer [N] = basketball) [Fruit] = Ar Ray ([0] = orange [8] = grape [9] = apple))

Here is a description:

Many people see why the "Apple" table above is "9"?

This question our previous article has said that the array subscript default is starting from 0, and then add 1, of course, you can also specify starting from a number, because we have defined the "grape" is 8, so the next "apple" subscript natural is 9. Do the little friends understand now?

The above example implements a two-dimensional array declaration, according to this idea, can declare the higher dimension of the array, is not very simple, if the two-dimensional array is still some unclear white, you can refer to our previous article "PHP array type-multidimensional array"!

"Related tutorials Recommended"

1. Related topics: "PHP array"

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.