3v4l.org

run code in 300+ PHP versions simultaneously
<?php function maybe_change_user_language( $selected_lang, $user_lang, $site_lang ) { if ( $selected_lang !== $site_lang ) { $user_lang = $selected_lang; } return $user_lang; } // Tests - Scroll to the bottom for results. function test_respect_user_language_preference( $expected, $site_lang, $user_lang, $selected_lang = 'English' ) { $user_lang = maybe_change_user_language( $selected_lang, $user_lang, $site_lang ); echo 'Expected: ', $expected, PHP_EOL; echo 'Actual: ', $user_lang, PHP_EOL; return 'Result: ' . ( $expected === $user_lang ? 'Pass' : 'Fail' ); } $tests = array( 'defaults with nothing selected' => array( 'expected' => 'English', 'site_lang' => 'English', 'user_lang' => 'English', 'selected_lang' => 'English', ), 'no existing preference and selects Spanish' => array( 'expected' => 'Spanish', 'site_lang' => 'English', 'user_lang' => 'English', 'selected_lang' => 'Spanish', ), 'already prefers Spanish and selects Spanish' => array( 'expected' => 'Spanish', 'site_lang' => 'English', 'user_lang' => 'Spanish', 'selected_lang' => 'Spanish', ), 'already prefers Spanish and selects nothing' => array( 'expected' => 'Spanish', 'site_language' => 'English', 'user_lang' => 'Spanish', 'selected_lang' => 'English', ), ); foreach ( $tests as $test => $args ) { $sep = str_pad( '', strlen( $test ), '=' ); echo $sep, PHP_EOL, $test, PHP_EOL, $sep, PHP_EOL; echo test_respect_user_language_preference( ...array_values( $args ) ), PHP_EOL, PHP_EOL; }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.1.70.0030.00317.30
8.1.60.0030.00617.62
8.1.50.0030.00617.53
8.1.40.0120.00417.50
8.1.30.0000.00817.53
8.1.20.0000.00817.54
8.1.10.0190.00517.34
8.1.00.0120.00017.21
8.0.200.0030.00317.00
8.0.190.0030.00516.95
8.0.180.0000.00716.89
8.0.170.0030.00516.95
8.0.160.0080.00016.91
8.0.150.0000.00816.91
8.0.140.0030.01116.79
8.0.130.0070.00516.87
8.0.120.0040.00916.82
8.0.110.0080.00416.79
8.0.100.0090.00616.64
8.0.90.0040.00816.74
8.0.80.0110.00016.74
8.0.70.0110.00016.79
8.0.60.0070.00716.82
8.0.50.0080.00416.77
8.0.30.0130.00316.88
8.0.20.0060.00616.88
8.0.10.0070.00316.89
7.4.300.0060.00016.52
7.4.290.0000.00816.42
7.4.280.0000.00816.61
7.4.270.0070.00616.42
7.4.260.0000.01116.34
7.4.250.0140.00016.35
7.4.240.0040.00816.30
7.4.230.0040.00916.48
7.4.220.0120.00416.41
7.4.210.0100.00316.49
7.4.200.0100.00516.46
7.4.190.0050.00516.57
7.4.180.0110.00316.48
7.4.160.0100.00316.50
7.4.150.0110.00816.35
7.4.140.0190.00016.31
7.4.130.0150.00316.29
7.4.120.0150.00316.36
7.4.110.0180.00016.50
7.4.100.0180.00016.38
7.4.90.0140.00516.39
7.4.80.0150.00316.29
7.4.70.0120.00616.44
7.4.60.0130.00616.38
7.4.50.0090.00916.32
7.4.40.0120.00616.39
7.4.30.0100.00716.45
7.4.20.0120.00516.32
7.4.10.0160.00316.23
7.4.00.0090.00916.42

preferences:
11.44 ms | 406 KiB | 5 Q