php遍曆json
有這樣一個數組$jobArr
$jobArr=array( 1 => array( 0 => array( 'name' => '產品經理1', 'desc' => '廣州' , 'mark' => 'group:1' ), 1 => array ( 'name' => '產品經理1', 'desc' => '廣州' , 'mark' => 'group:1'), 2 => array ( 'name' => '產品經理1', 'desc' => '廣州' , 'mark' => 'group:1') ), 2 => array ( 0 => array ( 'name' => '產品經理2' , 'desc' => '廣州' , 'mark' => 'group:2'), 1 => array ( 'name' => '產品經理2' , 'desc' => '廣州' , 'mark' => 'group:2')), 3 => array ( 0 => array ( 'name' => '產品經理3' , 'desc' => '廣州' , 'mark' => 'group:3' ), 1 => array ( 'name' => '產品經理3' , 'desc' => '廣州' , 'mark' => 'group:3')));
if($jobArr[$index]){ foreach($jobArr[1] as $post){ $jobList2 .= << {$post['name']} {$post['desc']} html; } foreach($jobArr[2] as $post){ $jobList3 .= << {$post['name']} {$post['desc']} html; } foreach($jobArr[3] as $post){ $jobList4 .= << {$post['name']} {$post['desc']} html; } }
在這裡我遍曆了三次,然後放在這三個div中,很麻煩,怎麼遍曆一次就可以將資料分類放在這幾個div中呢?
{ $jobList2} { $jobList3} { $jobList4}