Php multi-dimensional array FAQ

Source: Internet
Author: User
Php multi-dimensional array problem $ families & nbsp ;=& nbsp; array (& nbsp; "Griffin in" = & gt; array & nbsp; (& nbsp; & nbsp; "Peter", & nbsp; "Lois", small issues with php multi-dimensional array
$families = array
(
  "Griffin"=>array
  (
  "Peter",
  "Lois",
  "Megan"
  ),
  "Quagmire"=>array
  (
  "Glenn"
  ),
  "Brown"=>array
  (
  "Cleveland",
  "Loretta",
  "Junior"
  )
);


If an element is printed normally, it is written in this way.
$ Families [Griffin in] [0],
But I have seen it.
$ Families [Griffin [0],
What is the difference? where are they used?
------ Solution --------------------

// As mentioned on the #1 and #2 floors, there is indeed a problem with the second writing method for the example of the landlord.
// Modify the array if you really want a value.
$ Families = array
(
"Griffin in" => array
(
"Peter ",
"Lois ",
"Megan"
),
"Quagmire" => array
(
"Glenn"
),
"Brown" => array
(
"Cleveland ",
"Loretta ",
"Junior"
),
"Peter" => 9
);
$ Griffin in = array (
"Peter ",
"Lois ",
"Megan"
);
Print_r ($ families ['grip'] [0]);
Print_r ($ Griffin in [0]);
Print_r ($ families [$ Griffin in [0]);

------ Solution --------------------

// Retrieve the value of the "fmilies" array as [Griffin in] and [0]
$ Families [Griffin in] [0],
// Retrieve the value of the lower mark named fmilies array as [Griffin [0]
$ Families [Griffin [0],

The two statements have different meanings. the values in [] are the following table in the array.
The second method in this example is incorrect.
------ Solution --------------------
In 2nd, the meaning is not the same as that in the first method.

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.