Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102355 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93800 invoked from network); 21 Jun 2018 16:33:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jun 2018 16:33:16 -0000 Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.196 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.223.196 mail-io0-f196.google.com Received: from [209.85.223.196] ([209.85.223.196:35682] helo=mail-io0-f196.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4B/84-32156-B43DB2B5 for ; Thu, 21 Jun 2018 12:33:15 -0400 Received: by mail-io0-f196.google.com with SMTP id q4-v6so3568188iob.2 for ; Thu, 21 Jun 2018 09:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=saxSTaCGkNpljKfGdbMAw9x8qKFZcI7Xs9Y6OTs7Ing=; b=kKevY8CkaqWRPk+x61ESw+TFX5F4Hc6v6t1VY7pt6P4/5gcRmWoIXEqJTDcwib/qnT 9V00XuoXA4g6LN5flonat4cMHQ7YGjjOIGnr6OTJ/QB0gFwHx/e68v7gF7VJ7B4OfHYO Kg2VsJUgZ9XgzCQQ+owlV3TwHJp51/ynlMv8Fn0nucEnpng3yQK/LP42OmV6QgiiO2sT Rr4r4f3MpP/MDIBntluygU89HHUCxTqlDgIkdDFlG41tg8RFqWtK7dX2X1JHkjdmydDz aYnCE0DNNAfxNQZlgAxG/uylrCxMpc45w1P9b9hbRW+vS3cG13xK7TrhbZqz2xrKP/17 +xSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=saxSTaCGkNpljKfGdbMAw9x8qKFZcI7Xs9Y6OTs7Ing=; b=rZCC+TfDpVMb6hxud9lK0LQwbnyB6oG4ZEJbA4gqqE7l1eMC8qZ8jPicGcpJiYKHmw /Vb+qkUJ9E6IFqJPC/YFwa007b/ED95VGEQ5W1jaiQ2+R3mszM/r6QONRgGUW5iWOTVS 2cukMmufEDc1Hgo7YSlOXYe8Is4NPDwVR2IOgAPg8Cm3RQAvmgDhYXkLlp8JL+yIJIHV NyFUmLje+xOQ1kdcF4Ck4lNIU+jySeJEUPQ5Bnp5yeb02BZc80EnSB7vEuOTWM6L7AH2 fgowUSV37a1GauzsvhVnlYx1d/BcGpAmcYZnPsXwvjXT28E6DSr3BlSJ6oYmfh/HTa32 8whA== X-Gm-Message-State: APt69E1u3XUhfew+qt2OStIYq3ePbU4UAn8AG3xd9cAD52a88XtddkV7 qCrkurn0PaIQZE11ci0uFiVXKXdOTL21ATK7pbzqhQ== X-Google-Smtp-Source: ADUXVKKs9OOD9WxbgeP8FXHpeJ7NvObyj9aHcLO29b7PD9FTnptM+Z/mBIaLYqq6cAmbKvnBF6xtVKVAQcdJQLXHvd8= X-Received: by 2002:a6b:b387:: with SMTP id c129-v6mr22291768iof.195.1529598792716; Thu, 21 Jun 2018 09:33:12 -0700 (PDT) MIME-Version: 1.0 References: <75db877c-ef0b-7d3b-48a8-9879d90352b0@web.de> <3242366.BL9MUqXe46@vulcan> <2241856.Iz1GuBRvza@vulcan> In-Reply-To: <2241856.Iz1GuBRvza@vulcan> Date: Thu, 21 Jun 2018 13:33:01 -0300 Message-ID: To: Larry Garfield Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000b05641056f297899" Subject: Re: [PHP-DEV] [RFC][Under Discussion] Add functions array_key_first()and array_key_last() From: david.proweb@gmail.com (David Rodrigues) --000000000000b05641056f297899 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Brainstorm suggestions: 1. Keys being stored as reference: $valueOutput =3D array_first(array $array, ?string &$keyOutput =3D null); 2. Function will returns value or key, by option (similar to array_filter()): =E2=80=8B=E2=80=8B array_first(array $array, int $options =3D ARRAY_VALUE); =E2=80=8B =E2=80=8B array_first(array $array, int $options =3D ARRAY_KEY); =E2=80=8B =E2=80=8B3. =E2=80=8B F =E2=80=8Bunction will returns value or key, by boolean argument: array_first(array $array, bool $returnKeyInsteadOfValue =3D false); array_first(array $array, bool $returnKeyInsteadOfValue =3D true); =E2=80= =8B 4. Specific method to return key instead of value: array_first(array $array); array_first_key(array $array); 5. Consider that keys could be obtained via array_keys(), so array_first() should just care about values: array_first(array_keys($array)); Em qui, 21 de jun de 2018 =C3=A0s 13:18, Larry Garfield escreveu: > On Tuesday, June 19, 2018 9:47:01 PM CDT Levi Morrison wrote: > > I don't think I'm getting all the mail I am supposed to. I hope this ge= ts > > seen. > > > > I propose 2 functions *only* which I believe covers the use-cases that > > all 4 of these do and more, with shorter names, and the ability to > > discern whether the call succeeded or not. > > > > list($key, $value) =3D array_first($input); > > // $key will be null if the call failed > > > > list($key, $value) =3D array_last($input); > > // $key will be null if the call failed > > > > I have tested it with user-land functions and seems to work as > > intended in all success and failure conditions. Verification that it > > works as intended with internal functions is necessary but this seems > > a much better proposal to me. > > Can I vote "heck no" to any function that does multi-return, thus making > it > impossible to chain or pass directly to another function? That's an idio= m > that just doesn't make sense in PHP. > > --Larry Garfield --=20 David Rodrigues --000000000000b05641056f297899--