Why doesn\'t php support this syntax:
$s = explode(\'-\', \'foo-bar\')[0];
?
Instead you could use this if you'r force to use inline : substr($var,0, strrpos($var,'-')); But I prefer the list solution , it's more elegant !