On 20 June 2018 at 14:55, Levi Morrison <le...@php.net> wrote:

>
>     if ([$key, $value] = array_last($input) {
>         // do something
>     }
>
>

Unfortunately, this won't work. I didn't know list() could even be used as
an expression, but apparently if it is, it evaluates to the whole array on
its right-hand side, which makes sense.

So, if array_last([]) returns [null, null], then [$key,
$value]=array_last([]) will also evaluate to [null, null]. Since that's not
an empty array (it has two elements in it), it will evaluate to true.
https://3v4l.org/lIEa1

If, on the other hand, array_last([]) returned something empty, like [],
the list() assignment would throw Notices for the implicit access to
elements [0] and [1] of the empty array. https://3v4l.org/qhq5R

Regards,
-- 
Rowan Collins
[IMSoP]

Reply via email to