The question is how to get value from preg_match() function the shortest way possible.
Let say, I know my string ends with digits. I'm sure! 100%!! Its in stone!!! What I need, is the value...
So far I do
preg_match('/(\d+)$/', $mystring, $m);
echo $m[1];
Is there a way to do this in one line of code?
I tried:
echo preg_match('/(\d+)$/', $mystring, $m)[1];
Error returned....
Any ideas?
myFunction()[index]syntax is available in PHP 5.4: php.net/manual/en/migration54.new-features.phppreg_matchreturns an int.