php数组添加键,php – 为现有数组添加键和值

我需要为现有数组添加键和值,似乎无法将它们组合在一起.

打印时我现有的数组如下所示:

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

)

)

我需要从一个看起来像这样的字符串中动态添加一些细节到这个数组:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值