Parse error on explode('-','foo-bar')[0] (for instance)

前端 未结 4 1565
暗喜
暗喜 2020-12-11 22:46

Why doesn\'t php support this syntax:

$s = explode(\'-\', \'foo-bar\')[0];

?

4条回答
  •  时光说笑
    2020-12-11 23:23

    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 !


提交回复
热议问题