Loading [MathJax]/jax/output/HTML-CSS/jax.js
dongxia9519 2014-06-19 19:09
浏览 62
已采纳

围绕括号的PHP方括号

I am having trouble with my array and json_encode. I want it to look like this

"invites": [{
  "sent": 0,
  "accepted": 0
}],

but it looks like this

"shares": {
  "sent": 0,
  "installed": 0
},

Currently the code I am using looks like this

'shares' => array(
  'sent' => 0,
  'installed' => 0
),

Does anyone know how I would go about changing this. Thanks Matt

  • 写回答

2条回答 默认 最新

  • douyong4842 2014-06-19 19:12
    关注

    You have to wrap the (associative) array inside another one:

    'shares' => array(array(
       'sent' => 0,
       'installed' => 0,
    ))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部