3v4l.org

run code in 300+ PHP versions simultaneously
<?php function randomString(int $stringLength, array $parts, string $delimeter = ' ') : string { $keys = array_keys($parts); // Получаем массив ключей массива. Они упорядочены и идут с нулевого индекса. $count = count($keys); if (0 === $count) { return ''; } $text = []; for($i = 1; $i <= $stringLength; $i++) { // Больше нравится когда написано конкретно "с первого до последнего" $text[] = $parts[$keys[random_int(0, $count - 1)]]; // Получаем значение по случайному ключу из массива ключей } return implode($delimeter, $text); } echo randomString( 10, [ 'a' => 'lorem', 14 => 'ipsum', 'dolor' => 'dolor', 5 => 'sit', 'amet' => 'amet' ] );

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)
7.4.10.0090.00914.66
7.4.00.0110.00914.70
7.3.130.0110.00814.78
7.3.120.0080.00814.66
7.3.110.0100.00714.32
7.3.100.0080.00814.58
7.3.90.0100.01714.79
7.3.80.0060.01114.82
7.3.70.0100.00514.53
7.3.60.0090.00614.89
7.3.50.0080.01414.49
7.3.40.0110.00414.60
7.3.30.0110.00414.55
7.3.20.0110.00414.77
7.3.10.0040.01814.64
7.3.00.0100.00714.72
7.2.260.0090.00614.95
7.2.250.0070.01015.07
7.2.240.0090.00914.93
7.2.230.0120.00814.95
7.2.220.0000.01614.70
7.2.210.0050.01114.91
7.2.200.0070.01115.03
7.2.190.0060.00914.79
7.2.180.0090.00714.93
7.2.170.0110.00714.91
7.2.160.0100.00514.98
7.2.150.0100.00714.99
7.2.140.0100.01215.05
7.2.130.0110.00615.06
7.2.120.0120.00614.67
7.2.110.0030.01214.92
7.2.100.0000.01514.77
7.2.90.0000.01614.68
7.2.80.0110.00414.78
7.2.70.0090.00614.84
7.2.60.0050.01014.85
7.2.50.0070.00815.13
7.2.40.0070.00715.22
7.2.30.0070.00714.95
7.2.20.0080.00614.47
7.2.10.0370.00315.05
7.2.00.0090.00915.18

preferences:
36.75 ms | 401 KiB | 5 Q