3v4l.org

run code in 300+ PHP versions simultaneously
<?php var_dump(remove_last('bla test bla test bla test bla test bla', 'test', ' ')); function remove_last(string $text, string $subject, string $separator): string { $parts = explode($separator, $text); $pos = count($parts) -1 -array_search($subject, array_reverse($parts)); if ($parts[$pos] ?? false) { unset($parts[$pos]); } return implode($separator, $parts); }

preferences:
25.36 ms | 408 KiB | 5 Q