公告
财富商城
积分规则
提问
发文
2019-01-20 13:40发布
相关推荐>>
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 !
You can write it using list:
list
list($first_value) = explode(‘-’,‘foo-bar’);
The syntax ‘foo-bar’)[0] is wrong as far as php is concerned. I don't know which language you have seen such thing in but PHP has no implementation for such syntax. However, you can split your string like this:
‘foo-bar’)[0]
explode(‘-’, ‘foo-bar’);
It's a limitation in the PHP parser. There's no reason why it can't support this form of reduction, it just doesn't.
最多设置5个标签!
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 !
You can write it using
list
:The syntax
‘foo-bar’)[0]
is wrong as far as php is concerned. I don't know which language you have seen such thing in but PHP has no implementation for such syntax. However, you can split your string like this:It's a limitation in the PHP parser. There's no reason why it can't support this form of reduction, it just doesn't.