Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123161 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 249661A009C for ; Fri, 19 Apr 2024 19:34:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1713555324; bh=dfxDQquCLtx8B6VWqlLLI/1GdHH1Tuv/9nT5B/e+6FE=; h=From:Date:Subject:To:References:Cc:In-Reply-To:From; b=NPv95fDn40PqRCVOYBoFR6NkPuSgDIJx0ksBNA0VZpLzVBI0Ygj8IGB2weRFfijdg bAoWjOcy5WGd2xwl3Po3w9R0bIA0mTHJAx8/zTiceeGMBCBHC+lnJpTDICrN2FxJj2 4XrXKpkDCnR1+SuL5YOPoeyKieLCtB+Hw/MKolcUqNsef9vedmOqxuL0hapCseioRX VMkO98vXBtCBtHOiaBfDpRvBGcurOV/xTMI1XvSVb1WH/lCE31pnOQhzBOP+UOsr/C HF8z2y4LMNq5pv8/08jTomgoAogfQM3ROWvLWqTyRTH97srQu67Mtu3jh/SMgw6O05 xkcScz3NDu9mg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1D23C18074E for ; Fri, 19 Apr 2024 19:35:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 19 Apr 2024 19:35:23 +0000 (UTC) Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-516d3a470d5so3006551e87.3 for ; Fri, 19 Apr 2024 12:34:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wcflabs.de; s=google; t=1713555284; x=1714160084; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:cc:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=cDAn7Zkd3qRVBC99sukxVlO00061ZDQVKG4hU9yadJE=; b=bfikSqsAdqZ89rUISGxgN9xiOqb0sR+W6JiTy6t5xaqVyUPkJ36/6U+KtlhZmVP1pB cE1D1cNH6dduSmJtyUgprzO/vU7rpZBOMvpCn6/LM3McnVMpulE3m2c06HpBDm9VUkOc S8Xj5Zvnw6GR0EQ5OonTf6/wpTe0H56NC6bvqUWLzYpWUzJEf150oB77vCle2+3ON7SY ps2eX3HFT8EEToQjPNyulpn5PitN2m4WnquisEoGWeHGNCMGD3GnPwcfFtv0Sz8kSj/W Z6Sr1ZIw9RYwmDQ8OG/weR1GbkWLUIYrGCCZ4XRZ5k6+PPqQtaxoM6LrsqcPbnpQy6Pp YEDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713555284; x=1714160084; h=content-transfer-encoding:in-reply-to:cc:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cDAn7Zkd3qRVBC99sukxVlO00061ZDQVKG4hU9yadJE=; b=SeYOGYkFvTZqG47vGkRP7PUcFT/Fx2LXDEVmIIZbeZ5S2qmTb6OoF7tK18Frns62qL Sn5e0kpdzRn032E6U6V2GM/kobCUneV7kBCroOwLyWd9GDluyPIqZit0DD4o5LtNHhe+ qbvT2Y/1NyWu/ufYYENJ9RZHrm0ae4eRTDAMEWhjOtgXS7ZMnqlW2h4Ad0s2FpymwrXp 8mnUxwM+eD/YhEDsbWXS2J0+jf4mqyyClHe6F+wvje8vPbiefZDh3BXfn/BWOFK6WwES VjWMp7XqmAYPLg4JrYjlAWe+Fi4FDCfepprr/cW8IUs7bVN8t501G9CR0V7BGh4j1SV9 VnDA== X-Gm-Message-State: AOJu0YyYHoLSs180wrAiEg7hFG993hmiChqxkwzN8I7Q1uYxGho1uLG4 QwdqRW0N/u1bO87KbPuNBPhu2fdR8zgj6cLfBVuct5EB6xx151TH8XZIM+SlNfcgsXuxCXaTJjT O X-Google-Smtp-Source: AGHT+IGXPTQuw+ZI2sSCBxqybqqob8etqlkyGbhz6hqO1b8YnIt453hcDZ2MA9p5hqg1XiDnmwueUw== X-Received: by 2002:a05:6512:10c6:b0:51a:c44d:b95f with SMTP id k6-20020a05651210c600b0051ac44db95fmr2136743lfg.28.1713555283817; Fri, 19 Apr 2024 12:34:43 -0700 (PDT) Received: from ?IPV6:2a01:598:c000:b860:f477:8504:6874:238c? ([2a01:598:c000:b860:f477:8504:6874:238c]) by smtp.gmail.com with ESMTPSA id ky17-20020a170907779100b00a55926df215sm317478ejc.72.2024.04.19.12.34.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Apr 2024 12:34:43 -0700 (PDT) X-Google-Original-From: =?UTF-8?Q?Joshua_R=C3=BCsweg?= Message-ID: Date: Fri, 19 Apr 2024 21:34:42 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] RFC [Discussion]: array_find Content-Language: de-DE To: Larry Garfield References: <24e4529d-0b75-44de-90ef-34de5dfb1c99@wcflabs.de> <278889be-82ab-4827-a9e7-801b5ba2d8f8@app.fastmail.com> <45b726f4-8085-43e2-b701-6b35bc249409@wcflabs.de> <2dd7ef64-d1c5-4ed8-964f-b86dba110e0d@app.fastmail.com> Cc: PHP internals In-Reply-To: <2dd7ef64-d1c5-4ed8-964f-b86dba110e0d@app.fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit From: josh@wcflabs.de ("=?UTF-8?Q?Joshua_R=C3=BCsweg?=") Hi On 10.04.24 00:12, Larry Garfield wrote: > Another alternative is to always return the key, because you can trivially get the value from the key, but not vice versa. Of course, the resulting syntax for that is frequently fugly. > > $val = $array[array_find($db, $array)] ?? some-default; In 95% (roughly) of cases, I (personally) need the array value and not the key. Just having the option to get the key is already a step forward compared to the current state, but I personally would find it impractical (and fugly, as you said) to use the method, especially if the search callback is more complex and multi-line (and it is fugly, as you said). Here is an example for this, without using a helper variable: $value = $array[\array_find($array, function ($value, $key): bool { if ($key % 5) { return \strlen($value) < 100; } if ($key % 2) { return \strlen($value) < 40; } return false; })]; So I think, this is not an option. Cheers Josh