"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How Do I Extract Specific Values From a Multidimensional PHP Array?

How Do I Extract Specific Values From a Multidimensional PHP Array?

Published on 2024-11-10
Browse:590

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:

$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'
    ]
];

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:

echo $myarray[0]['email']; // Outputs: [email protected]

Similarly, if you wanted to get the gender, you would use:

echo $myarray[0]['gender']; // Outputs: male
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3