//有這樣一個數組$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')));
//在這裡我遍曆了三次,然後放在這三個div中,很麻煩,怎麼遍曆一次就可以將資料分類放在這幾個div中呢? 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; } }
{ $jobList2} { $jobList3} { $jobList4}
回複內容:
//有這樣一個數組$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')));
//在這裡我遍曆了三次,然後放在這三個div中,很麻煩,怎麼遍曆一次就可以將資料分類放在這幾個div中呢? 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; } }
{ $jobList2} { $jobList3} { $jobList4}
是要這個效果嗎?
php
$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')));foreach($jobArr as $k=>$v){ $html=array(); foreach($v as $key=>$val){ $html[$val['mark']]['html'].="{$val['name']}{$val['salary']}"; } $div.="".$html[$val['mark']]['html']."";}echo $div;