二维数组合并内容成一维数组
??array_reduce($data, 'array_merge', array());
用array_reduce()函数是较为快捷的方法
例:
array(2) { [0]=> array(6) {
[0]=> string(1) "7"
[1]=> string(1) "8"
[2]=> string(1) "9"
}
[1]=> array(3) {
[0]=> string(1) "6"
[1]=> string(1) "8"
[2]=> string(2) "13"
}
}
array_reduce($data, 'array_merge', array());
结果: array(6) {
[0]=> string(1) "7"
[1]=> string(1) "8"
[2]=> string(1) "9"
[3]=> string(2) "6"
[4]=> string(2) "8"
[5]=> string(2) "13"
}
$promotedSeq = array_column($users, 'promotedSeq'); 排序字短集合
array_multisort($promotedSeq,?SORT_DESC,?$studentData);
$promotedSeq = array_column($users, 'promotedSeq');排序字短集合1
$promotedTime = array_column($users, 'promotedTime');排序字短集合2
array_multisort($promotedSeq, SORT_ASC, $promotedTime, SORT_DESC, $users);
数组分割
array(6) {
[0]=> string(1) "7"
[1]=> string(1) "8"
[2]=> string(1) "9"
[3]=> string(2) "6"
[4]=> string(2) "8"
[5]=> string(2) "13"
}
array_chunk($cars,3)
结果: array(2) { [0]=> array(6) {
[0]=> string(1) "7"
[1]=> string(1) "8"
[2]=> string(1) "9"
}
[1]=> array(3) {
[0]=> string(1) "6"
[1]=> string(1) "8"
[2]=> string(2) "13"
}
}
|