Re: Two new functions array_first() and array_last()

From: Date: Tue, 17 Oct 2023 18:42:59 +0000
Subject: Re: Two new functions array_first() and array_last()
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-121361@lists.php.net to get a copy of this message
> There is also a technique to make the return value [$key => > $value] instead of just a value, but this loses simplicity. Hmm, since the naming array_first and array_last doesn't clarify that it's returning a key or a value. What if it returned both as ?[key, value]. That opens quite a few use possibilities: $first = array_first($array); $value = $first[1] ?? throw new Exception(); [,$value] = array_first($array) ?? [null, null]; [,$value] = array_first($array) ?? throw new Exception();

« previous php.internals (#121361) next »