方法1:
$arr = array(array(
0=> array('a'=>1),
1=> array('a'=>3),
2=> array('a'=>4),
3=> array('a'=>3),
4=> array('a'=>1),
5=> array('a'=>3),
6=> array('a'=>4),
7=> array('a'=>2),
8=> array('a'=>1),
9=> array('a'=>4),
));
foreach($arr as $k=>$v){
foreach ($v as $kvs=>$vs){
echo $vs['a'];
}
}
$array = array(1);
foreach($arr as $k=>$ar){
array_map(function ($item) use (&$result,$array,$k) {
static $count;
if (!isset($count[$item['a']])) {
$count[$item['a']] = 0;
}else{
$count[$item['a']]++;
}
echo $count[$item['a']].'==>'.$item['a'].'<br>';
$result[] = $count[$item['a']];
},$ar);
}
方法2:
$arr = array(
0=>1,
1=>3,
2=>4,
3=>6,
4=>1,
5=>3,
6=>4,
7=>2,
8=>1,
9=>4
);
$test = array();
foreach ($arr as $k=>$v){
$test[$v][] = $k;
}
$test2 = array();
foreach ($test as $k1=>$v1){
$ss = 0;
foreach ($v1 as $k2=>$v2){
$test2[$v2] = $ss;
$ss++;
}
}
ksort($test2);
var_dump($test2);
0=>1,
1=>3,
2=>4,
3=>6,
4=>1,
5=>3,
6=>4,
7=>2,
8=>1,
9=>4
);
$test = array();
foreach ($arr as $k=>$v){
$test[$v][] = $k;
}
$test2 = array();
foreach ($test as $k1=>$v1){
$ss = 0;
foreach ($v1 as $k2=>$v2){
$test2[$v2] = $ss;
$ss++;
}
}
ksort($test2);
var_dump($test2);