將上圖的陣列輸出為下圖格式的
多謝!!
將上圖的陣列輸出為下圖格式的
多謝!!
如果確定第三維固定只有一個鍵值對的話,第三重循環可以忽略
<code>$result_arr = array(); foreach($arr as $key => $data){ foreach($data as $val) { $second_key = key($val); $result_arr[$key][$second_key] = $val[$second_key]; } }</code>
<code>$arr = array( '初级' =>array( 0=>array( 2=>95, ), 1=>array( 3 => 423, ) ), '二级' => array( 0=>array( 4=>22, ), 1=>array( 5 => 43, ) ), ); foreach ($arr as $key => $value) { foreach ($value as $k => $v) { foreach ($v as $ks => $vs) { $arrs[$key][$ks] = $vs; } } } var_dump($arr); var_dump($arrs);</code>