3v4l.org

run code in 300+ PHP versions simultaneously
<?php $versions = [ '1', '1.0.2.4', '1.1.0', '1.12.547.8' ]; $max = 0; $new = preg_replace_callback_array( [ "/(\d+).?/" => function($m)use(&$max){ if(($new = strlen($m[1])) > $max) $max = $new; return $m[0]; }, "/(\d+)$|(\d+.)/" => function($m)use(&$max){ return str_pad($m[0], ($m[1] !== "" ? $max : $max+1), "0", STR_PAD_LEFT); } ], $versions); print_r($new);
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 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.18, 8.3.0 - 8.3.6
Array ( [0] => 001 [1] => 001.000.002.004 [2] => 001.001.000 [3] => 001.012.547.008 )
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28
Fatal error: Call to undefined function preg_replace_callback_array() in /in/T5nnf on line 6
Process exited with code 255.

preferences:
185.49 ms | 402 KiB | 212 Q