array_push() 带键值对 [英] array_push() with key value pair
本文介绍了array_push() 带键值对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要添加值的现有数组.
I have an existing array to which I want to add a value.
我正在尝试使用 array_push()
来实现这一目标,但无济于事.
I'm trying to achieve that using array_push()
to no avail.
下面是我的代码:
$data = array(
"dog" => "cat"
);
array_push($data['cat'], 'wagon');
我想要实现的是将 cat 作为键添加到 $data
数组中,以 wagon 为值,以便访问它如以下代码段所示:
What I want to achieve is to add cat as a key to the $data
array with wagon as value so as to access it as in the snippet below:
echo $data['cat']; // the expected output is: wagon
我怎样才能做到这一点?
How can I achieve that?
推荐答案
那么拥有:
$data['cat']='wagon';
这篇关于array_push() 带键值对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文