配列の配列があり、すべての内部配列には 4 つの文字列と 1 つの int が含まれています。
現在、私は a を使用して配列を移動しておりforeach
、内側の配列を番号 (最後のアイテム) で並べ替えて、より高い/大きいものが最初になるようにしてから、並べ替えられた新しい配列にそれらを転送する方法を探しています。その方法。
$twoDUnsorted = array(
array(
0=>"the",
1=>"quick",
2=>"brown",
3=>"fox",
4=>650
),
array(
0=>"jumps",
1=>"over",
2=>"the",
3=>"lazy",
4=>420
),
array(
0=>"it",
1="was",
2=>"the",
3=>"worst"
4=>1016
),
array(
0=>"of",
1=>"times",
2=>"it",
3=>"was",
4=>768
),
array(
0=>"the",
1=>"best",
2=>"of",
3=>"times,
4=>123
)
);
次に、for each を使用して移動し、各内部配列の最後の項目で並べ替えてから、array_push を使用して配列を新しい 2D 配列に順番にプッシュします。
したがって、新しい 2D 配列は次のようになります。
$twoDSorted = array(
array(
0=>"it",
1="was",
2=>"the",
3=>"worst"
4=>1016
),
array(
0=>"of",
1=>"times",
2=>"it",
3=>"was",
4=>768
),
array(
0=>"the",
1=>"quick",
2=>"brown",
3=>"fox",
4=>650
),
array(
0=>"jumps",
1=>"over",
2=>"the",
3=>"lazy",
4=>420
),
array(
0=>"the",
1=>"best",
2=>"of",
3=>"times,
4=>123
)
);
I would appreciate any and all help sorting them and pushing them into the new array in order.