duannian7116 2016-02-13 06:39
浏览 503
已采纳

从php laravel 5中的数组中的数组中获取键值

I just want to get the value which is in array with in array. Following is my array.

I have a variable called $checklist.

$checklist = Checklist::where('equipment_id', Input::get('id'))->get()->toArray();

when I var_dump($checklist) it gives the following result.

array (size=2)
0 => 
array (size=10)
'id' => string 'a953fd4a509b41e0b12a1385aef7bca9' (length=32)
'checklist_template_id' => string '5d9ef7a83a4943c9a9580fd22d1dae2a' (length=32)
'ordre_id' => string '8b3392e34ff545b488d6623b2a27e7f5' (length=32)
'equipment_id' => string 'a797d64908024babb7e1eb4fc9167b78' (length=32)
'status' => string '' (length=0)
'image' => string '' (length=0)
'comment' => string '' (length=0)
'deleted_at' => null
'created_at' => string '2016-02-12 11:33:45' (length=19)
'updated_at' => string '2016-02-12 11:33:45' (length=19)
1 => 
array (size=10)
'id' => string 'ba5e4e822e5c44ba96132a9f196dc896' (length=32)
'checklist_template_id' => string '5d9ef7a83a4943c9a9580fd22d1dae2a' (length=32)
'ordre_id' => string '8b3392e34ff545b488d6623b2a27e7f5' (length=32)
'equipment_id' => string 'a797d64908024babb7e1eb4fc9167b78' (length=32)
'status' => string '' (length=0)
'image' => string '' (length=0)
'comment' => string '' (length=0)
'deleted_at' => null
'created_at' => string '2016-02-12 10:16:19' (length=19)
'updated_at' => string '2016-02-12 10:16:19' (length=19)

All I want is, get "checklist_template_id" alone... how can I get it? can anyone help me with it???

Thanks in advance.

  • 写回答

3条回答 默认 最新

  • douxi1968 2016-02-13 07:12
    关注

    You can achieve this by looping your array as below

    $result = array();
    foreach($checklist as $key=> $val)
    {
      $result[] = $val['checklist_template_id'];
    }
    
    print_r($result);
    

    this should help you.

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

报告相同问题?

悬赏问题

  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。