Home > Backend Development > PHP Tutorial > How to Access Single Values in Multi-Dimensional PHP Arrays?

How to Access Single Values in Multi-Dimensional PHP Arrays?

Patricia Arquette
Release: 2024-11-04 07:39:02
Original
425 people have browsed it

How to Access Single Values in Multi-Dimensional PHP Arrays?

Retrieving Single Values from Multi-Dimensional PHP Arrays

This multi-dimensional array is structured as an array containing another array within its [0] index. To access specific values within this structure, you need to navigate through the array using the appropriate indexes.

Obtaining Single Values:

The following examples demonstrate how to obtain single values from the provided array:

<code class="php">echo $myarray[0]['email']; // Output: [email protected]

echo $myarray[0]['gender']; // Output: male</code>
Copy after login

Explanation:

  • $myarray[0] accesses the first (and only) element in the main array.
  • $myarray[0]['email'] accesses the email value within the first sub-array.
  • Similarly, $myarray[0]['gender'] accesses the gender value.

By understanding the structure of your multi-dimensional array and utilizing the appropriate indexes, you can easily retrieve individual values.

The above is the detailed content of How to Access Single Values in Multi-Dimensional PHP Arrays?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template