Results of 1 - 1 of about 1 for TestObj (0.000 sec.)
- usort — ユーザー定義の比較関数を使用して、配列を値でソートする | PHP 8.3 9414
- usort (PHP 4, PHP 5, PHP 7, PHP 8) usort — ユーザー定義の比較関数を使用して、配列を値でソートする 説明 function usort ( array &$array , callable $callback ): true 順序を決めるユーザー定義の比較関数により、 array をその値でソートします。 注意
... と $b は配列の最初のインデックスへの参照を保持しています。 例3 usort() でオブジェクトのメンバ関数を使用する例 <?php class TestObj { public string $name ; function __construct ( $name ) { $this -> name = $name ; } /* これは、比較用のstaticメソッドです * ... / static function cmp_obj ( $a , $b ) { return strtolower ( $a -> name ) <=> strtolower ( $b -> name ); } } $a [] = new TestObj ( "c" ); $a [] = new TestObj ( "b" ); $a [] = new TestObj ( "d" ); usort ( $a , [ TestObj ::class, "cmp_obj" ]); foreach ( ...
-
https://man.mtool.work/php/8.3/function.usort.html
PREV
1
NEXT