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
Patricia ArquetteOriginal
2024-11-04 07:39:02423browse

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>

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!

Statement:
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