douliang2087 2016-11-21 23:03
浏览 40
已采纳

从多个复选框的Php数组

I'm working with laravel, and I'm a bit stuck in getting the right structure I want of the value, so I have a check box like this:

<input type="checkbox"  name="permission[]" value="{{$permission->slug}}"> {{$permission->name}}

And this outputs me this:

array:2 [
    0 => "dashboard.view"
    1 => "user.edit"
]

But what I really need to store is something like this:

{"dashboard.view":true,"user.edit":true}
  • 写回答

2条回答 默认 最新

  • dtukyb8095 2016-11-21 23:31
    关注

    This should be what you're looking for:

    <input type="checkbox"  name="permission[{{$permission->slug}}]" value="true"> {{$permission->name}}
    

    Should give you an associative array on the backend you can call json_encode on if you need to store it as a json object.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作