Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91120 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68959 invoked from network); 8 Feb 2016 16:05:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2016 16:05:28 -0000 Authentication-Results: pb1.pair.com header.from=kinncj@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=kinncj@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.41 as permitted sender) X-PHP-List-Original-Sender: kinncj@gmail.com X-Host-Fingerprint: 209.85.213.41 mail-vk0-f41.google.com Received: from [209.85.213.41] ([209.85.213.41:33750] helo=mail-vk0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/D4-36326-7CCB8B65 for ; Mon, 08 Feb 2016 11:05:27 -0500 Received: by mail-vk0-f41.google.com with SMTP id k196so31516106vka.0 for ; Mon, 08 Feb 2016 08:05:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=LlaIq3YYNuH4X7h9MGqHt6Y+Kfi0+YcxWrxhmP4TVsE=; b=Pa5uFysg6iNX/dhjnqvpH07Jd/D5QPbxlDhfHbCKiqcgAXzN/xmor2+exIAUFC2dyt 4Q4m3kQSBqvSLYey26J9PtjjNT7WWrdPEIzirLaBMHKtEOHufEv6ltCXGmhKgTa/0SSC 5eWJm0j+FFeRuxoEr0gpcOoP7Nu4ziqzFY2u0taEOe50R4tgxH0IiTfwGndfhbyZM/F5 jNdWWLZ6zpOyFo3z9bXzIDduN9eeKsSpL2aXf3VRhDw9WjZJUdYYjw9pq0LV8o3J6Ycm iFVj3Calh1z/KJfG/wWnminoXzqLRhloILxddR/b3ApUDFyiGGRfClPcqVMkS/xIRwiu uKsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=LlaIq3YYNuH4X7h9MGqHt6Y+Kfi0+YcxWrxhmP4TVsE=; b=ZoaveL3A6NcQH24XS6P2ghdWXrcz30DfjD6m4qdOcUYpn5+k+NGQBf+FLIWnxFzRw2 GhrB1eSevIOCgJJUVH1qnjj/d+9hC3KdcahoaswsDJ07oYCqMZPKQnp3ygT5UEC1UAMK F/4rZ06haKCzzCYne4/3jrgBCvhvWxKKyCBuRPfTbbngsrC1d2A7egrKvLdPw6Om18bu F0synIkoR+8Q+eYr8HsYae62QnT3DZkeayWl4zpaQTVK+KWSSLdP1xrfT4SLNFx4ODPw TII8O3CqtqmwA+wYsOB7byBbuKR71yTDbvcj6qNWYIBSk31Ee9T1HKfBJtGsad8lDIVm KZrg== X-Gm-Message-State: AG10YOQAWpG01AtKyOmzOTpXKv/liP8MAJiKh1jFhu9ONPoPyir7LorEO4wusz3ztwvLbWORWXi6pTomKhSHlw== X-Received: by 10.31.133.201 with SMTP id h192mr20837673vkd.102.1454947525007; Mon, 08 Feb 2016 08:05:25 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.52.23 with HTTP; Mon, 8 Feb 2016 08:05:05 -0800 (PST) In-Reply-To: References: Date: Mon, 8 Feb 2016 11:05:05 -0500 Message-ID: To: Matthew Setter Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=001a114119a265224a052b445e1b Subject: Re: [PHP-DEV] Proposal for a new array function From: kinncj@gmail.com (=?UTF-8?B?S2lubiBKdWxpw6Nv?=) --001a114119a265224a052b445e1b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Feb 8, 2016 at 9:32 AM, Matthew Setter wrote= : > I want to propose a new PHP array method, called has_numeric_keys (or > something similar/better), that would have the following method signature= : > > bool has_numeric_keys(array $array) > > The reason for it is to check if the array passed to it only had numeric > keys. > > Why this method, when you could do it in userland PHP? Answer? Convenienc= e. > I found, recently, that I had to perform this kind of check, when patchin= g > Zend\Db\Sql\Insert.php. The approach I took was this: > > return array_keys($arr) !=3D=3D range(0, count($arr) - 1); > > Not sure of my approach, I took to Twitter and received the following > suggestions, amongst others: > > function isArrNum($arr) { > foreach($arr as $i =3D>$v){ > if (!is_int($i)) { > return false; > } > } > return true; > } > > count(array_filter(array_keys($array), 'is_string')) > 0 > > array_filter([...], 'is_int', ARRAY_FILTER_USE_KEY) > > This convinced me that it wasn't just me seeing a valid use case for it, > and that others have implemented differing solutions when presented with > the same situation. Given that, I believe a simple, utility, function suc= h > as this would be of help. > That's the nice thing about userland... you are giving them ability to implement what they want! `array_filter([...], 'is_int', ARRAY_FILTER_USE_KEY)` does the job as the others... don't think having a new function would prevent this. > > As for who would implement it, that would be me. > > -- > Kind regards, > > > *Matthew Setter* > *Freelance Software Developer & Technical Writer * > *Host of Free the Geek | Author of Zend Framework > 2 > Foundations * > > w: http://www.matthewsetter.com > t: *@settermjd * > g+: *+MatthewSetterFreelanceWriterDeveloper > >* > li: *in/matthewsetter * > --=20 *--* *Kinn Coelho Juli=C3=A3o* *Toronto - ON/Canada* --001a114119a265224a052b445e1b--