我需要向现有数组添加键和值,但似乎无法做到。
当打印时,我的现有数组看起来像这样:
Array
(
[0] => stdClass Object
(
[id] => 787
[name] => Steve
[surname] => Ryan
[email] => Steve@hotmail.com
)
[1] => stdClass Object
(
[id] => 1057
[name] => Peter
[surname] => Smith
[email] => Peter.Smith@yahoo.com
)
[2] => stdClass Object
(
[id] => 1058
[name] => Chris
[surname] => Gill
[email] => chrisgill@gmail.com
)
)
我需要在运行时从一个类似于这样的字符串中添加一些细节到这个数组中:
string
。Topher:Topher1234@mac.com
Elvis:elvispresley@gmail.com
Marilyn:marilyn.monroe@hotmail.com
每个条目都由一个
新行
分隔,并且名称和电子邮件地址由:
分隔。因此,最终我的数组将如下所示:
Array
(
[0] => stdClass Object
(
[id] => 787
[name] => Steve
[surname] => Ryan
[email] => Steve@hotmail.com
)
[1] => stdClass Object
(
[id] => 1057
[name] => Peter
[surname] => Smith
[email] => Peter.Smith@yahoo.com
)
[2] => stdClass Object
(
[id] => 1058
[name] => Chris
[surname] => James
[email] => chrisjames@gmail.com
)
[3] => stdClass Object
(
[id] =>
[name] => Topher
[surname] =>
[email] => Topher1234@mac.com
)
[4] => stdClass Object
(
[id] =>
[name] => Elvis
[surname] =>
[email] => elvispresley@gmail.com
)
[5] => stdClass Object
(
[id] =>
[name] => Marilyn
[surname] =>
[email] => marilyn.monroe@hotmail.com
)
)
我查看了array_push但是无法理解。
非常感谢任何对此的帮助。
C
array_push
函数或者直接使用$array['key'] = $value
。 - Erik