简体   繁体   English

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

[英]get key value from array within array in 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 = Checklist::where('equipment_id', Input::get('id'))->get()->toArray();

when I var_dump($checklist) it gives the following result. 当我var_dump($ checklist)给出以下结果。

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? 我只想要一个人获取“ checklist_template_id” ...我怎么能得到它? can anyone help me with it??? 有人可以帮我吗???

Thanks in advance. 提前致谢。

You can achieve by using below example: 您可以使用以下示例来实现:

 $donor_details = array();
    $return_arr_1 = array();
       foreach ($donor_loc as $key=>$value)
                    {

                        $donor_details['name']=$value->full_name;
                        $donor_details['contact']=$value->contact_number;
                        $return_arr_1[] = $donor_details;
                    }
    print_r($return_arr_1 );

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. 这应该对您有帮助。

You can try array_column 您可以尝试array_column

$checklist_template_ids = array_column($checklists, 'checklist_template_id');

If you which to index the resulting array by checklists id, so you can make something like id => checklist_template_id then simply include it as third argument like so 如果您要通过检查清单ID为结果数组建立索引,那么您可以制作类似id => checklist_template_id然后将其作为第三个参数包含在内,如下所示

$checklist_template_ids = array_column($checklists, 'checklist_template_id', 'id');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM