I have a script trimming strings this way billions of times.
$s = substr($s, 0, -$n);
Is there a way to do it faster an without reassigning the string?
I have a script trimming strings this way billions of times.
$s = substr($s, 0, -$n);
Is there a way to do it faster an without reassigning the string?
By definition strings are not mutable in PHP. To "cut" a string, you'll have to create a new string based on the original string, making it necessary to reassign it. The code you have is probably already the most minimalist way to do it.