2016-11-25 37 views
5

我有一個數組如何從laravel表單請求中獲取密鑰?

array:2 [▼ 
    2 => "12" 
    7 => "12" 
] 

從形式發送,我需要的2和7我如何稱呼他們?

這些鍵是部件編號所需的。 的foreach獲得ID和值 然後更新的東西...

foreach($request->except('_token') as $part) { 
    /*get Key here (in this case 2 or 7) and get value here (in this case both 12)*/ 
} 

有人可以告訴我如何做到這一點?

在此先感謝。

回答

7

使用$key => $value符號在foreach

foreach ($request->except('_token') as $key => $part) { 
    // $key gives you the key. 2 and 7 in your case. 
} 
5
$data = $request->except('_token') 
foreach($data as $id => $value){ 
    echo "My id is ". $id . " And My value is ". $value; 
}