Home > Article > Backend Development > How Do I Extract Specific Values From a Multidimensional PHP Array?
Obtaining Single Values from Multidimensional PHP Arrays
When working with multidimensional PHP arrays, situations may arise where you need to access specific values within the array. Consider the following example:
<code class="php">$myarray = [ [ 'id' => 6578765, 'name' => 'John Smith', 'first_name' => 'John', 'last_name' => 'Smith', 'link' => 'http://www.example.com', 'gender' => 'male', 'email' => '[email protected]', 'timezone' => 8, 'updated_time' => '2010-12-07T21:02:21+0000' ] ];</code>
To access specific values within this array, you need to use the appropriate array indices and keys. For instance, to obtain the email address, you would use the following code:
<code class="php">echo $myarray[0]['email']; // Outputs: [email protected]</code>
Similarly, if you wanted to get the gender, you would use:
<code class="php">echo $myarray[0]['gender']; // Outputs: male</code>
The above is the detailed content of How Do I Extract Specific Values From a Multidimensional PHP Array?. For more information, please follow other related articles on the PHP Chinese website!