简体   繁体   中英

change value of a key of an array within an array in php?

I have an array within an array like:

$some_large_array = array(
    'person' => array('name' => 'stefanie', 'hobby' => 'rock climbing',),
    'dog' => array('name' => 'orbit', 'hobby' => 'chewing curtains'));

How can I change the value of of 'hobby' of 'dog' and return it as 'napping'?

You can access array keys like this, in your example:

$some_large_array['dog']['hobby'] = 'napping';

(answering to remove from "unanswered" queue)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM