How to use a two-dimensional array in PHP

Source: Internet
Author: User
The recent need to use a two-dimensional array in PHP, a simple example to illustrate how the two arrays in PHP using <?php$a=array (' A ', ' B ', ' C '), $c =array (' A1 ', ' B1 ', ' C1 '); $b =array (' id ' =   >18, ' count ' =>27, $a, $c); echo $b [' id '];  18echo $b [' count '];  echo $b [0][0];  Aecho $b [0][1];  Becho $b [0][2];  Cecho $c [1][0];  A1echo $c [1][1];  B1echo $c [A];  C1?> Note the order of the one-dimensional values of the two arrays in the example above, $b an array with two elements in front of it, and an array starting from $ A. This time if you want to take the first element in a $ A array should be $b [0][0] instead of $b[1][0] Speaking here again my previous mistakes, although more stupid, but also hope that some like me more novice php beginners warning, hehe ~ ~ Note The following is an example of the error I used to think if I defined is $a=array (' id ' =>18, ' count ' =78) Then echo $a the output value of [' ID '] should be equivalent to echo $a [0] later lost the command only to discover that this is not the case. It turns out that this is related to how the array is defined in the following way $a=array (' id ' =>18, ' count ' =78) should be used $a [' ID '] and if defined in the way $a=array (' 18 ', ' 78 ') should be used $a[0]

How to use a two-dimensional array in PHP

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.