[英]Adding an array in an existing key in an associative array PHP
Title sounds a bit convoluted but the title itself is pretty self-descriptive I think. 标题听起来有点令人费解,但我认为标题本身是非常自我描述的。
Assume that I have an associative array like this: 假设我有一个像这样的关联数组:
$data['blog_info'] = array(
"title" => "Adventure",
"author" => "Yo"
);
Now, I would like add to the current key 'blog_info" another set of key => value array. so the result should be : 现在,我想向当前键“ blog_info”添加另一组键=>值数组,因此结果应为:
$data['blog_info'] = array(
"title" => "Adventure",
"author" => "Yo",
"ISBN" => "23423498"
);
so for example I would like to add "ISBN" => "23423498" inside this 'blog_info' key. 因此,例如,我想在此“ blog_info”键中添加“ ISBN” =>“ 23423498”。 How am I able to achieve this?
我怎样才能做到这一点? (but by going like $data['blog_info'].push("ISBN" => "23423498") etc?)
(但是像$ data ['blog_info']。push(“ ISBN” =>“ 23423498”)等)?
下面将实现它( $data['blog_info']
只是一个数组)。
$data['blog_info']['ISBN'] = '23423498';
In PHP you don't need the curly braces {
and }
in this context. 在PHP中,在这种情况下,不需要花括号
{
和}
。
$data['blog_info'] = array(
"title" => "Adventure",
"author" => "Yo"
);
Try something like 尝试类似
$data['blog_info']['ISBN'] = '23423498';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.