Why php does not support this syntax:
$s = explode('-', 'foo-bar')[0];
?
This is a limitation in the PHP parser. There is no reason why he cannot support this form of contraction, just not.
You can write it with list:
list
list($first_value) = explode(‘-’,‘foo-bar’);
‘foo-bar’)[0] php. , , PHP . :
‘foo-bar’)[0]
explode(‘-’, ‘foo-bar’);
Instead, you can use this if you are forced to use inline: substr ($ var, 0, strrpos ($ var, '-')); But I prefer a list solution, it's more elegant!
Source: https://habr.com/ru/post/1735795/More articles:Ocaml exception handling for open input channel - matchingIs learning a standard C ++ library a good idea? - c ++Using Valid HTML 4.01 Strictly with Django - html5Connection pool in Java SE? - javaКак использовать проверку перекрестной проверки с помощью MATLAB? - matlabHow can I scroll through each letter in MS Word using VBA? - ms-wordProblems with jQuery, JSON and Apache - jsonVisual Studio cannot find native tool EntityModelCodeGenerator - asp.net-mvcimport strategy in django applications - pythonSCJP question: ambiguous method - javaAll Articles