Heim > Fragen und Antworten > Hauptteil
ringa_lee2017-05-27 17:45:57
<?php
$arr = [
[1,'A'],
[2,'B'],
[3,'C'],
[4,'D'],
[5,'A'],
[6,'B'],
[7,'C'],
[8,'D']
];
$temp = [];
foreach($arr as $value){
if(array_key_exists($value[1],$temp)){
array_push($temp[$value[1]],$value);
}else{
$temp[$value[1]] = [];
array_push($temp[$value[1]],$value);
}
}
var_dump(array_values($temp));
PHPz2017-05-27 17:45:57
$arr=array(
array(1=>'A'),
array(2=>'B'),
array(3=>'C'),
array(4=>'D'),
array(5=>'A'),
array(6=>'B'),
array(7=>'C'),
array(8=>'D'),
);
$res=array();
foreach ($arr as $key => $value) {
foreach ($value as $k => $v) {
$res[$v][$k]=$v;
}
}
$res=array_values($res);
echo "<pre>";print_r($res);die();