2016-02-13 142 views
0

我只想獲取數組中的數組的值。 以下是我的數組。從數組中的數組中獲取鍵值php laravel 5

我有一個名爲$ checklist的變量。

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

當我var_dump($清單)它給出了以下結果。

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) 

我只想得到「checklist_template_id」......我怎麼能得到它?任何人都可以幫助我嗎?

在此先感謝。

回答

0

您可以通過循環的陣列如下

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

print_r($result); 

這應該可以幫助您實現這一目標。

0

您可以嘗試array_column

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

如果該索引所產生的清單ID陣列,這樣你就可以做出類似id => checklist_template_id然後簡單地把它作爲第三個參數,像這樣

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

你可以用下面的例子來實現:

$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);