3v4l.org

run code in 300+ PHP versions simultaneously
<?php function esc_attr( $string ) { return $string; } function sanitize_key( $key ) { return $key; } function test( $choices ) { foreach( $choices as $key => $value ) { if ( is_integer( $key ) ) { $field_name = "field[$key]"; } elseif ( is_string( $key ) ) { $field_name = sprintf( 'field[%s]', sanitize_key( $key ) ); } else { // may want to throw an error here. } printf( '<input name="%s" value="1"/>', esc_attr( $field_name ) ); echo "\n"; } } echo "An indexed array\n"; $choices = array( 'Red', 'Blue', 'Green' ); test( $choices ); echo "\n\nAssociative array\n"; $choices = array( 'red' => 'Red', 'blue' => 'Blue', 'green' => 'Green' ); test( $choices );

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.3.60.0070.01418.18
8.3.50.0100.01018.23
8.3.40.0180.00018.49
8.3.30.0140.00718.53
8.3.20.0110.00424.18
8.3.10.0070.00024.66
8.3.00.0110.00426.16
8.2.180.0090.01225.92
8.2.170.0070.00722.96
8.2.160.0120.00922.96
8.2.150.0070.01125.66
8.2.140.0030.00624.66
8.2.130.0150.00326.16
8.2.120.0060.00320.44
8.2.110.0070.00322.09
8.2.100.0060.00617.91
8.2.90.0030.00617.71
8.2.80.0060.00317.63
8.2.70.0060.00317.48
8.2.60.0080.00317.80
8.2.50.0030.00518.07
8.2.40.0040.00417.91
8.2.30.0070.00017.64
8.2.20.0000.00720.63
8.2.10.0080.00017.73
8.2.00.0040.00419.23
8.1.280.0070.01125.92
8.1.270.0050.00523.99
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0030.00622.14
8.1.230.0030.00922.68
8.1.220.0050.00220.88
8.1.210.0050.00318.87
8.1.200.0030.00617.23
8.1.190.0040.00417.23
8.1.180.0050.00318.10
8.1.170.0050.00218.74
8.1.160.0020.00518.89
8.1.150.0000.00718.64
8.1.140.0070.00017.49
8.1.130.0030.00320.27
8.1.120.0000.00917.47
8.1.110.0000.00717.34
8.1.100.0040.00417.31
8.1.90.0000.00717.45
8.1.80.0070.00317.46
8.1.70.0040.00417.48
8.1.60.0050.00317.59
8.1.50.0050.00317.54
8.1.40.0060.00317.46
8.1.30.0000.00917.64
8.1.20.0040.00417.52
8.1.10.0040.00417.50
8.1.00.0120.00217.29
8.0.300.0040.00422.09
8.0.290.0030.00516.75
8.0.280.0000.00718.44
8.0.270.0040.00416.82
8.0.260.0060.00018.49
8.0.250.0040.00416.98
8.0.240.0040.00416.97
8.0.230.0030.00316.97
8.0.220.0040.00416.84
8.0.210.0050.00316.82
8.0.200.0030.00316.88
8.0.190.0040.00416.84
8.0.180.0000.00716.93
8.0.170.0030.00516.94
8.0.160.0050.00316.87
8.0.150.0000.00816.79
8.0.140.0000.00816.85
8.0.130.0100.00216.69
8.0.120.0130.00816.85
8.0.110.0100.01016.84
8.0.100.0140.00516.82
8.0.90.0110.00716.85
8.0.80.0130.00616.77
8.0.70.0070.01316.79
8.0.60.0130.00716.87
8.0.50.0160.00416.79
8.0.30.0090.01016.71
8.0.20.0160.00616.89
8.0.10.0170.00216.96
8.0.00.0070.00517.02
7.4.330.0040.00015.55
7.4.320.0000.00616.63
7.4.300.0030.00316.49
7.4.290.0050.00216.44
7.4.280.0000.00716.50
7.4.270.0000.00716.36
7.4.260.0080.00416.47
7.4.250.0150.00316.45
7.4.240.0170.00416.64
7.4.230.0140.00516.45
7.4.220.0160.00316.46
7.4.210.0150.00316.63
7.4.200.0160.00316.42
7.4.190.0080.00316.59
7.4.180.0030.01016.54
7.4.160.0140.00016.55
7.4.150.0110.00716.49
7.4.140.0190.00016.57
7.4.130.0120.00416.29
7.4.120.0160.00616.42
7.4.110.0110.00816.51
7.4.100.0120.00916.51
7.4.90.0180.00416.36
7.4.80.0100.01116.35
7.4.70.0190.00316.40
7.4.60.0210.00016.37
7.4.50.0190.00316.20
7.4.40.0140.00716.25
7.4.30.0150.00416.46
7.4.20.0210.00016.50
7.4.10.0160.00516.29
7.4.00.0140.00716.51
7.3.330.0170.00716.36
7.3.320.0110.00816.20
7.3.310.0110.00316.23
7.3.300.0150.00716.32
7.3.290.0090.00616.16
7.3.280.0080.01416.34
7.3.270.0070.00716.33
7.3.260.0080.00416.36
7.3.250.0120.00516.11
7.3.240.0170.00415.85
7.3.230.0070.00816.09
7.3.220.0110.00615.89
7.3.210.0110.00415.70
7.3.200.0170.00016.06
7.3.190.0110.00815.99
7.3.180.0120.00516.01
7.3.170.0150.00415.86
7.3.160.0110.00416.17
7.3.150.0120.00415.75
7.3.140.0110.00616.21
7.3.130.0170.00016.05

preferences:
60.06 ms | 400 KiB | 5 Q