3v4l.org

run code in 300+ PHP versions simultaneously
<?php $aliases = [ 'foo', 'bar-1', 'joomla-23', 'joom-0', ]; foreach ($aliases as &$alias) { $alias = preg_replace_callback( '~(?:-\K\d+)?$~', function ($m) { return strlen($m[0]) ? 1 + $m[0] : '-2'; }, $alias, 1 ); } var_export($aliases);
Output for 7.3.13 - 7.3.33, 7.4.0 - 7.4.29, 8.0.0 - 8.0.19, 8.1.0 - 8.1.6
array ( 0 => 'foo-2', 1 => 'bar-2', 2 => 'joomla-24', 3 => 'joom-1', )

preferences:
36.33 ms | 409 KiB | 5 Q