I have array which is presenting like this:
我有这样的数组:
$array = array (
"list" => array(
"serwer-1" => 3
),
"servers" => array(
3 => array(
"msg" => "{'some data': 123123121313}",
"status" => 200
),
),
);
I want add new items to $array['list'] for example:
我想在$ array ['list']中添加新项目,例如:
array (
"list" => array(
"serwer-1" => 3
//NEW DATA HERE
"serwer-2" => 7,
),
"servers" => array(
3 => array(
"msg" => "{'some data': 123123121313}",
"status" => 200
),
),
);
Maybe it's trivial, but I haven't any idea how to do this - I have bad day today :(
也许这是微不足道的,但我不知道如何做到这一点 - 我今天有糟糕的一天:(
1 个解决方案
#1
1
In order to add a key-value pair to an existing array just do it like the key exists there.
为了将键值对添加到现有数组,只需要像那里存在的键一样。
$array["list"]["serwer-2"] = 7;
Then you will get desired result.
然后你会得到理想的结果。
#1
1
In order to add a key-value pair to an existing array just do it like the key exists there.
为了将键值对添加到现有数组,只需要像那里存在的键一样。
$array["list"]["serwer-2"] = 7;
Then you will get desired result.
然后你会得到理想的结果。