我有一個數組$ ARR:得到陣列PHP的foreach父鍵
Array
(
[2] => Array
(
[status] => 0
[item] => Food Processer
[catagory] => Appliance
)
[23] => Array
(
[status] => 1
[item] => 12 cup medium muffin tray
[catagory] => Kitchenware
)
[24] => Array
(
[status] => 1
[item] => 24 cup mini muffin tray
[catagory] => Kitchenware
) etc...
我想對每個元素的錶行結束:
<tr id="2" class="0"><td>Food Processer</td><td>Appliance</td></tr>
我當前的代碼是:
foreach ($arr as $a)
{
echo('<tr id="'.key($a).'" class="'.$a['status'].'">');
echo('<td>');
echo($a['item']);
echo('</td>');
echo('<td>');
echo($a['catagory']);
echo('</td>');
echo('</tr>');
}
,但我得到的狀態鍵(字符串「狀態」)作爲id的值我怎樣才能得到父$ ARR鍵即(2,23,24)。
你的東東做的foreach($數組作爲$鍵=> $值) – Daniel 2013-03-22 00:01:23