Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127068 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 968291A00BC for ; Mon, 7 Apr 2025 19:29:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1744054010; bh=088Xglc1G/biGjAQwwtJ4fAAnTCXPFpMXQsyfCz6J/Y=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Q/kySQZu4zF62LbYvgbN8OHdhpo9HJrPQnzgcO68SRHbNZcbxvcbySre2+ZC3c8a2 Ui/U/jVkTGAVrsnbKljwpV7GA2W4P9b+/HmY4vrXSK/l665HDM5ExsEN3vFxX9R9RL lJWfLdmqNXHGl4ILCiZlPQ/zxcNuC4PFOJTnXaR+FZoBsX1l8uC98Hrals/xp75Np8 gQOVpGdPjg2m37E/eRgLpN9ijIh2l7BEaqSWhhbbb94lyJymK4wFVA9gvHgwoPYBuG 6Dvw3QbIx1ODKjxQzx4OGl1S9xhMYww2gSTn8O752I1OrnQupflNgiK2sJN8Yz2G5J 0o1Z4VFAEAx1Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DFB6E18007E for ; Mon, 7 Apr 2025 19:26:49 +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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 ; Mon, 7 Apr 2025 19:26:49 +0000 (UTC) Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-43cf680d351so34163135e9.0 for ; Mon, 07 Apr 2025 12:29:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744054153; x=1744658953; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=g5DTIpB/T1g/vZySHWEulv81oJ3CJGiZ5fkOcR3gBMg=; b=TA1thrl/Y7SHBmTbdGvewaIqvOcTX4m5+TEbw2NEHpEGPAofjS7Vojb2UZ/nCrceTK aYjzqKP2i1yEgqF6S+44te8F2IZ45fD858wtnPXsF5fU0a7mDRWSCLZSx2gEpdxqV42h Wx7AS/faAoWRGad8Einvfdt1CPPtkqfdUeUzlotxuqjykLYdPfdbrwTPXDh4rapM5Fm8 uDGEYxf3s+/4KU2gf5KnxCg/dQd0ZK4mZxxe7RPWqyLbw4EJxJXfqQvRBBdahS+9GT8D C1wzmRU3L+uffY1Ocr0LyRteVZF8UMXNu7Y++DtV7vSf5BBcHLLf4jmnsfjm6nBUlVar J7uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744054153; x=1744658953; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=g5DTIpB/T1g/vZySHWEulv81oJ3CJGiZ5fkOcR3gBMg=; b=SOhKjE4GEOHDsRacjB+xzCxNxQPkyNok13QVVV6919ilXEyLFc0gQWy8xLUDFloFW4 Op3f84OdlhulNqtfBELlXu+U0kYpsT3t7hOrtsV+g9JYWbsF51vS8xw9SPODzX16p7L5 4BOj3ssFH5IlCOwJ73UAEVYezwmfnkbpF4SHrAh4iOqc2pnfZZBN8j5ig2UcpY6N2vUK I0Nrab6lQBeLztNaQZUPbV8rdgZSzFwQaWvJGq7P0G917Al2CZ4rAk57T28OYuGE2UZp JczkmLj3HvROaxYiaIhAU2XO5slKZ4KoywWhPYX0JmfhA260ooxb9qFbli6lFdZNleoV OyfA== X-Gm-Message-State: AOJu0YxSeV6ZmT8el1vICkHS7tJIf4oq24i6o6NGlpLZmr3DO6o0U/J2 ZhqIQBysmdp25DtYx5TRAiUzVL2DoS4uX4Dbq3Bhy0AFeLC+aZ/uwFa1DQ== X-Gm-Gg: ASbGnctWqqxqKHUnxjfkT81SbbWbGepRzoLFOxpMlLtIrPH4oH9BFLszbw74AaItVXo 1s25mt9cYT2jSrqeHo/U/5tsTyelF+1/aoLDMylmt4t1wh8A5/MzloY/Faf8ajdRwaX/g4M3fdJ 8rAR/+mU1U/YeLU0hV4nmNUK+488SwQYeI612iVn2G3dHogzU00AWkgfPU2uTzKOXKhvJi/zSqv U716Jlr0ydo/2hB/Gs0VYMZDQmocJfZtBZklh3RKmFUJ8DC6LugO1NBjnyC7xTVCZkUGogVy9N3 xKUX179NIEbVAuuWF7c3ds74plu71yeas9L4XlQzjRYWzcEcmUw8Qltxoh9D/D7GApLqbJz5Zyl nsichtaTsNH+7hJR7WlMLxo6xAvZOoYui1Rua3r30xRa6ea3FhjQRYw/nmhmsgXBdYbrFhVblqE Xe00uypdDh X-Google-Smtp-Source: AGHT+IGQezEPcLKFZcp71xTb0svhtLgAkWZUR75IWGP9NbFowTpUr+yZRIAuOZuUmKiaq6shcIdbXg== X-Received: by 2002:a5d:648c:0:b0:39c:dfa:e86c with SMTP id ffacd0b85a97d-39d820b3f78mr578827f8f.13.1744054152999; Mon, 07 Apr 2025 12:29:12 -0700 (PDT) Received: from ?IPV6:2a02:1811:cd2f:3500:e093:fcad:4f6:e542? (ptr-du5vm7f5ekzptmf0fgi.18120a2.ip6.access.telenet.be. [2a02:1811:cd2f:3500:e093:fcad:4f6:e542]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c301ba2dfsm13017843f8f.60.2025.04.07.12.29.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Apr 2025 12:29:12 -0700 (PDT) Message-ID: <2d6ae137-688f-4a76-9402-4fc42fe887cd@gmail.com> Date: Mon, 7 Apr 2025 21:31:23 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last() To: PHP internals References: <51fcec92-b2ae-482e-920f-c6c991b526c5@gmail.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: dossche.niels@gmail.com (Niels Dossche) On 06/04/2025 19:06, Juris Evertovskis wrote: > On 2025-04-05 18:51, Niels Dossche wrote: > Do you think it would be hard or wrong to add `array_nth`? I've had more trouble with that as the in-place implementation is usually pretty unreadable, e.g. > >     array_slice(array_values($array), $offset, 1)[0] ?? null > > I understand this need is less common, especially compared to `array_first`. But I also suspect that an in-engine implementation might have more performance gains compared to an userland one. > This is not hard to add. For packed arrays this can be done in O(1) time, for non-packed arrays in O(n) worst case. If added, it's best to add the pair array_nth() & array_nth_key() together IMO. However, it's not something I ever really needed nor something that I have seen a demand for. I think this could be left for the future for follow-up work. Kind regards Niels