0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

rsort関数について

Posted at

概要

競プロの練習課題でrsortを使うことがあったのですが、挙動について把握できておらず少しハマったので備忘録で残します

rsort

降順に並び替える関数

メモ

ソートしたデータは以下のように変数に格納する必要があると思っていました。

$array = [2,10,30,1,3,50];
$rsort = rsort($array);
foreach($rsort as $v){
    echo $v;
}

しかし、rsort関数は元の変数に変更を加えます。
なので、以下が正しいです。上記の書き方だとエラーになります。

$array = [2,10,30,1,3,50];
rsort($array);
foreach($array as $v){
    echo $v;
}

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?