3v4l.org

run code in 300+ 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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
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 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
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:
156.82 ms | 411 KiB | 5 Q