function sepPersons($persons, $indexs, $countArr){
$num1 = count($persons);
$num2 = count($persons[$indexs[0]]);
$iCount = count($indexs);
$count = $num1 * $num2;
$persons_names = array();
$countPad = array_pad(array(), $iCount, 0);
$getCount = array_combine($indexs, $countPad);
$m = 0; //m:0--7
$n = 0; //n:0--5
for($i=0; $i < $count; $i++){
$n = $i % $num2; //n:第二级下标;m:第一级
//判断是否要取$persons[$cIndex ]
if($n == 0 && $i > 0){
$m ++;
}
if( isset($indexs[$m]) ){
$cIndex = $indexs[$m];
if( !empty( $countArr[$cIndex] ) && isset($persons[$cIndex]) && $persons[$cIndex][$n]['name'] != '' && $getCount[$cIndex] < $countArr[$cIndex] ){
//若数量取够了不再取了
$persons_names[$cIndex][] = $persons[$cIndex][$n];
$getCount[$cIndex] ++ ;
unset($persons[$cIndex][$n]);
}
}
}
foreach ($persons as $key=> $value){
$persons[$key] = array_merge(array(), $value); //将第二级下标重组
}
return array('persons_names' =>$persons_names, 'persons_noNames' =>$persons);
}
$personsImgs = sepPersons($persons, $indexs, $countArr);
var_dump($personsImgs['persons_names']);
$persons = array(
1=>array(
array(
'id' =>1,
'name' =>'dfas',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>2,
'name' =>'dfs',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>3,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'dfde',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'few',
'age' =>23,
'say' =>'hello'
),
),
2=>array(
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'dgeg',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'gesd',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'fd',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'sdg',
'age' =>23,
'say' =>'hello'
),
),
3=>array(
array(
'id' =>1,
'name' =>'gre',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'ge',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'erg',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'gere',
'age' =>23,
'say' =>'hello'
),
),
5=>array(
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'wg',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'grd',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'fwe',
'age' =>23,
'say' =>'hello'
),
),
7=>array(
array(
'id' =>1,
'name' =>'ds',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'sfs',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'sasd',
'age' =>23,
'say' =>'hello'
),
),
11=>array(
array(
'id' =>1,
'name' =>'fse',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'sgwe',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'dfs',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'fse',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
),
17=>array(
array(
'id' =>1,
'name' =>'fse',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'fewgr',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'yryrte',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'tewrt',
'age' =>23,
'say' =>'hello'
),
),
22=>array(
array(
'id' =>1,
'name' =>'tere',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'ewhsf',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'wer',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'',
'age' =>23,
'say' =>'hello'
),
array(
'id' =>1,
'name' =>'y5yr',
'age' =>23,
'say' =>'hello'
),
)
);
$indexs = array(2, 3, 5, 22);
$countArr = array(
2=>1,
3=>4,
5=>3,
);
阅读(1456) | 评论(0) | 转发(0) |