3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rfcs = ['Typed Properties', 'PHP Attributes', 'Functional Interfaces', 'Closure from callable function', 'Forbid dynamic calls to scope introspection functions', 'Callable prototypes']; $numberOfCharsBeforeTrimRequired = 150; $perRFC = (int)($numberOfCharsBeforeTrimRequired / count($rfcs)); $done = []; do { $lastTrimNeeded = count($rfcs); $remaining = 0; foreach ($rfcs as $i => $rfc) { if (strlen($rfc) <= $perRFC) { $done[] = $rfc; $remaining += $perRFC - strlen($rfc); unset($rfcs[$i]); } } $perRFC += (int)($remaining / count($rfcs)); } while ($lastTrimNeeded > count($rfcs)); foreach ($rfcs as $rfc) { $done[] = substr($rfc, 0, $perRFC); } // get total length to check algo $totalLen = 0; foreach ($done as $rfc) { $totalLen += strlen($rfc); } var_dump($done, $totalLen);
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.31, 7.1.0 - 7.1.23, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array(6) { [0]=> string(16) "Typed Properties" [1]=> string(14) "PHP Attributes" [2]=> string(21) "Functional Interfaces" [3]=> string(19) "Callable prototypes" [4]=> string(30) "Closure from callable function" [5]=> string(50) "Forbid dynamic calls to scope introspection functi" } int(150)

preferences:
153.05 ms | 405 KiB | 288 Q