3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', ]; function multisort($array) { array_multisort(array_map('strlen', $array), SORT_DESC, $array); printf( "Total strlen() calls: %d\n%s\n---\n", count($array), var_export($array, true) ); } function usersort($array) { usort( $array, function($a, $b) { echo "strlen() called twice\n"; return strlen($b) <=> strlen($a); } ); var_export($array); echo "\n---\n"; } multisort($array); usersort($array);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
Total strlen() calls: 9 array ( 0 => 'eight', 1 => 'seven', 2 => 'three', 3 => 'five', 4 => 'four', 5 => 'nine', 6 => 'one', 7 => 'six', 8 => 'two', ) --- strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice array ( 0 => 'three', 1 => 'seven', 2 => 'eight', 3 => 'four', 4 => 'five', 5 => 'nine', 6 => 'one', 7 => 'two', 8 => 'six', ) ---
Output for 7.4.0 - 7.4.33
Total strlen() calls: 9 array ( 0 => 'eight', 1 => 'seven', 2 => 'three', 3 => 'five', 4 => 'four', 5 => 'nine', 6 => 'one', 7 => 'six', 8 => 'two', ) --- strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice strlen() called twice array ( 0 => 'seven', 1 => 'three', 2 => 'eight', 3 => 'four', 4 => 'five', 5 => 'nine', 6 => 'one', 7 => 'two', 8 => 'six', ) ---

preferences:
89.59 ms | 1416 KiB | 4 Q