0

大きな配列を作成し、それを並べ替えます。たとえば、並べ替えられた配列の最初の n 個の要素を取得する必要があります。

配列を作成:

foreach ($array_RESPONSEdata as $key => $row) {
 $new_created_time[$key] = $row['DATE_PIC'];
 $new_thumbnail[$key] = $row['LINK_PIC'];
 $new_tags_name [$key] = $row['TAG_PIC'];
}

get 配列の出力では、次のようになります。

Array (
[0] => Array ( [DATE_PIC] => 1376566005 [LINK_PIC] => http://distilleryimage3.s3.amazonaws.com/90ebfcc2059d11e381c522000a9e035f_5.jpg [TAG_PIC] => test )
[1] => Array ( [DATE_PIC] => 1376222415 [LINK_PIC] => http://distilleryimage9.s3.amazonaws.com/957a78a4027d11e3a72522000a1fb586_5.jpg [TAG_PIC] => test )
[2] => Array ( [DATE_PIC] => 1374685904 [LINK_PIC] => http://distilleryimage2.s3.amazonaws.com/1dbe356ef48411e2931722000a1fc67c_5.jpg [TAG_PIC] => test )
[3] => Array ( [DATE_PIC] => 1373909177 [LINK_PIC] => http://distilleryimage0.s3.amazonaws.com/0fd9b22adce711e2a7ab22000a1f97eb_5.jpg [TAG_PIC] => test )
[4] => Array ( [DATE_PIC] => 1372089573 [LINK_PIC] => http://distilleryimage0.s3.amazonaws.com/0fd9b22adce711e2a7ab22000a1f97eb_5.jpg [TAG_PIC] => test )
[5] => Array ( [DATE_PIC] => 1371468982 [LINK_PIC] => http://distilleryimage0.s3.amazonaws.com/0fd9b22adce711e2a7ab22000a1f97eb_5.jpg [TAG_PIC] => test )
)

次に、キー DATE_PIC で配列を並べ替えます。

array_multisort($new_created_time, SORT_DESC, $array_RESPONSEdata);

逆ソートで配列を取得します。


質問: 並べ替え後の出力の最初の 3 行はどうですか?

4

1 に答える 1