问题不是很清楚,请提供一些预期输出的清晰示例。无论我理解什么,您都可以尝试这样的代码:
$arr=array("1" => "name1", "2" => "game4", "3" => "game10", "4" => "game2",
"5" => "game3", "6" => "name4", "7" => "game4", "8" => "game10",
"9" => "game2", "10" => "game3", "11" => "name3", "12" => "game4",
"13" => "game10", "14" => "game2", "15" => "game3");
$narr = array();
for ($i=0; $i<count($arr)/5; $i++)
$narr[] = array_slice($arr, $i * 5, 5, true);
function cmp($a, $b) {
return strcmp(reset($a), reset($b));
}
uasort($narr, 'cmp');
print_r($narr);
输出:
Array
(
[0] => Array
(
[1] => name1
[2] => game4
[3] => game10
[4] => game2
[5] => game3
)
[2] => Array
(
[11] => name3
[12] => game4
[13] => game10
[14] => game2
[15] => game3
)
[1] => Array
(
[6] => name4
[7] => game4
[8] => game10
[9] => game2
[10] => game3
)
)