3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function stringMultiplicate($first, $second) { // Create array include result of 1 number in $second string * first $result = []; $strFirst = (string)$first; $strSecond = (string)$second; $maxLength = 0; for ($i = strlen($strSecond) - 1; $i >= 0; $i--) { $index = $i; $number = (int)$strSecond[$i]; $result[$index] = ''; $k = strlen($strSecond) - 1 - $i; $div = 0; for ($j = (strlen($strFirst) - 1); $j >= 0; $j--) { while ($k != 0) { $result[$index] .= '0'; $k--; } $next = ($number * $strFirst[$j] + $div); if (strlen($next) > 1 && $j != 0) { $result[$index] .= ((string)$next)[strlen($next) - 1]; $div = ((string)$next)[0]; } else { $result[$index] .= $number * $strFirst[$j] + $div; $div = 0; } } if (strlen($result[$index]) > $maxLength) { $maxLength = $result[$index]; } $result[$index] = strrev($result[$index]); } $multi = []; for ($j = 0; $j < $maxLength; $j++) { $sum = 0; for ($i = 0; $i < count($result); $i++) { var_dump($result[$i]); if (!isset($result[$i][$j])) { $result[$i][$j] = 0; } $sum += (int)$result[$i][$j]; } $multi[$j] = $sum; } return $multi; } var_dump(stringMultiplicate(12345, 123)); var_dump(12345*123);
based on c1drQ

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).
Note: hhvm uses a JIT which only kicks in after a few runs. Since we run scripts only once, hhvm always runs slower.

VersionSystem time (s)User time (s)Memory (MiB)
7.3.00.0120.00516.12
7.2.130.0120.01016.46
7.2.120.0150.00716.43
7.2.110.0140.00616.52
7.2.100.0120.00816.64
7.2.90.0100.01116.54
7.2.80.0150.00416.48
7.2.70.0100.01116.72
7.2.60.0100.01116.80
7.2.50.0120.00816.86
7.2.40.0190.00316.79
7.2.30.2620.00616.85
7.2.20.0110.01116.83
7.2.10.0080.01316.81
7.2.00.0120.00916.93
7.1.250.0140.00915.60
7.0.330.0120.00815.61
5.6.380.0100.00513.98