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);

preferences:
32.76 ms | 408 KiB | 5 Q