//如何把下面这个这个数组$arr=array(0=>array('id'=>1,'pid'=>),1=>array('id'=>208,'pid'=>),2=>array('id'=>3,'pid'=>208)3=>array('id'=>4,'pid'=>208));变成这样的形式的$arr=array(0=>array('id'=>1,'pid'=>),1=>array('id'=>208,'pid'=>,'str'=>array( 0=>array( 'id'=>1,'pid'=>208), 1=>array('id'=>4,'pid'=>208))));
http://bbs.csdn.net/topics/370094009
$brr=array();foreach($arr as $k=>$v){ if( empty($v['pid']) ) if( isset($brr[$v['id']]) ) { $brr[$v['id']][]=$v['id']; $brr[$v['id']][]=$v['pid']; }else $brr[$v['id']]=$v; else{ if(!isset($brr[$v['pid']])) $brr[$v['pid']]=array(); $brr[$v['pid']]['str'][]=$v; }}sort($brr);
http://bbs.csdn.net/topics/370094 009
Array( [1] => Array ( [id] => 1 [pid] => ) [4] => Array ( [id] => 4 [pid] => 208 ) [208] => Array ( [id] => 208 [pid] => [child] => Array ( [4] => Array ( [id] => 4 [pid] => 208 ) ) ))
$brr=array();foreach($arr as $k=>$v){ if( empty($v['pid']) ) { if( !isset($brr[$v['id']]) ) $brr[$v['id']]=$v; }else{ if(!isset($brr[$v['pid']])) $brr[$v['pid']]=array(); $brr[$v['pid']]['str'][]=$v; }}sort($brr);