3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_phrases($sentence) { $inQuotes = false; $quoteChars = ['"', "'"]; $separators = [' ', "\n"]; $phrase = null; foreach ((string) $sentence as $i => $t) { if (!$inQuotes && in_array($t, $quoteChars)) { // Opening quote $inQuotes = $t; } elseif ($inQuotes && $t == $inQuotes) { // Closing quote $inQuotes = false; } elseif (!$inQuotes && in_array($t, $separators)) { yield $phrase; // or add to an array in pre-5.5 $phrase = null; } else { $phrase .= $t; } } } var_dump(get_phrases('Hello world')); var_dump(get_phrases("I am a 'foo bar'");

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)
5.4.290.0100.05512.51
5.4.280.0170.04412.41
5.4.270.0150.04512.41
5.4.260.0110.06312.41
5.4.250.0110.05312.41
5.4.240.0150.06712.41
5.4.230.0120.06412.40
5.4.220.0120.05212.40
5.4.210.0180.06912.40
5.4.200.0110.05812.40
5.4.190.0100.05812.40
5.4.180.0080.06012.40
5.4.170.0090.07212.40
5.4.160.0090.05812.40
5.4.150.0090.05812.40
5.4.140.0150.06112.09
5.4.130.0100.05812.07
5.4.120.0090.06012.03
5.4.110.0110.06212.03
5.4.100.0120.06112.03
5.4.90.0130.05812.03
5.4.80.0070.06012.03
5.4.70.0090.05812.03
5.4.60.0090.05712.03
5.4.50.0100.05612.03
5.4.40.0070.06212.01
5.4.30.0110.05412.01
5.4.20.0140.05312.01
5.4.10.0100.06012.01
5.4.00.0100.05811.50
5.3.280.0130.05712.71
5.3.270.0090.06512.72
5.3.260.0110.06012.72
5.3.250.0120.06512.72
5.3.240.0090.06512.72
5.3.230.0120.06012.71
5.3.220.0150.06012.68
5.3.210.0100.05812.68
5.3.200.0070.06012.68
5.3.190.0150.05212.68
5.3.180.0100.06012.67
5.3.170.0090.08012.67
5.3.160.0150.05912.67
5.3.150.0070.05212.67
5.3.140.0100.05212.66
5.3.130.0090.05612.66
5.3.120.0110.05712.66
5.3.110.0100.05712.66
5.3.100.0110.04912.13
5.3.90.0080.05412.11
5.3.80.0100.04912.09
5.3.70.0110.04912.09
5.3.60.0090.04712.09
5.3.50.0130.04612.02
5.3.40.0100.04712.02
5.3.30.0090.05011.98
5.3.20.0080.04911.76
5.3.10.0090.05811.74
5.3.00.0130.06311.71

preferences:
137.62 ms | 1394 KiB | 7 Q