Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91142 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50110 invoked from network); 9 Feb 2016 11:19:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2016 11:19:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=matthew@maltblue.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=matthew@maltblue.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain maltblue.com from 209.85.223.173 cause and error) X-PHP-List-Original-Sender: matthew@maltblue.com X-Host-Fingerprint: 209.85.223.173 mail-io0-f173.google.com Received: from [209.85.223.173] ([209.85.223.173:33996] helo=mail-io0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 00/81-39202-D4BC9B65 for ; Tue, 09 Feb 2016 06:19:42 -0500 Received: by mail-io0-f173.google.com with SMTP id 9so14260616iom.1 for ; Tue, 09 Feb 2016 03:19:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maltblue-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=iKxcuy3hV+UGwMa2+xgB1j5+WpGlJ2tVTorMfzZI7HQ=; b=0AYVsGqwxo7EINXmlZku4iY3ROqUaFbLngWrnQFPSKt0Zpy2w/128SR42a1y0XAnTl sq9CcUkijAIXhr+T7GLtDLibaydgybBgPfyuqSVWEm2GUpR5FHJ1gaO+IOCz8WHYGRHA CJwGIe9XyUwSASt1SEAnUKcYUuvGldZ22E5b09+TWfntZr1NhKbI4SnGk6m5UACq2ea4 tdF2OQxFvOSKIoYf3rJf0itUJyMNHkjEwQMUrgYtJXDFq8wsdRZc81SgN9WdR8ZW41K9 SUfos237mOpI2V4wtL8/8nC/mPYiWUr5CQ5ikLHYqQqR7fa9hfsv39q/EG0dPpuB61Lh YLiw== 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:date :message-id:subject:from:to:cc:content-type; bh=iKxcuy3hV+UGwMa2+xgB1j5+WpGlJ2tVTorMfzZI7HQ=; b=f5qsVD+lRLsKjGvYE1Umf0V3A4Fq9K/ZYb8yGADU8dDeLZUZYeZzA84yZAa5VwXjMA 81t4hVss8FC+ntCsVke3fIq7s1hDZ2Ut+roXvtkO/eulxBlVt408H1jLgCesvsmNxyXo WGkrDkre09nTs5XB6S82abxHpVi3xkBZ7BxmKOMjhhSYBRzaOakKbAua3+OT1uYCN3dS btj6A5l3ieaN3Zj166JYtD/SzLeRmi8cMfBamEMCyJCCfHOmEtacI0lYOwcTi9vag9/+ 50mE3/ZMYNCJwKmIUi0m2zrTa8BEjr+DfMGZVfT+/2znxl9Ks40NnMng+xn4NJFlSI2l gzFQ== X-Gm-Message-State: AG10YOT/qB7F28BP3o+IjVBSqsTkW3Z0k3ehmhwiy3ZhWJAy4xAA140tj3REHhfZE5C/5tmAc45Ru6mQngNokw== MIME-Version: 1.0 X-Received: by 10.107.63.134 with SMTP id m128mr31748412ioa.116.1455016779307; Tue, 09 Feb 2016 03:19:39 -0800 (PST) Received: by 10.79.4.195 with HTTP; Tue, 9 Feb 2016 03:19:39 -0800 (PST) X-Originating-IP: [94.217.28.125] In-Reply-To: <56B8D3D9.3040904@mprelu.de> References: <56B8D3D9.3040904@mprelu.de> Date: Tue, 9 Feb 2016 12:19:39 +0100 Message-ID: To: Matt Prelude , piere.php@gmail.com, francois@php.net, gen.work@gmail.com, kinncj@gmail.com Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=94eb2c06151e460038052b547e32 Subject: Re: [PHP-DEV] Proposal for a new array function From: matthew@maltblue.com (Matthew Setter) --94eb2c06151e460038052b547e32 Content-Type: text/plain; charset=UTF-8 Thanks kindly for the rapid and very helpful feedback. I'm going over it today and will collate it and think over it further. Given that the feedback's been so constructive and positive, I'll be getting started on an RFC over the next day or so. Matt -- 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 * On Mon, Feb 8, 2016 at 6:43 PM, Matt Prelude wrote: > Hi, > >> 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? >> Convenience. >> I found, recently, that I had to perform this kind of check, when patching >> Zend\Db\Sql\Insert.php. The approach I took was this: >> >> return array_keys($arr) !== 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 =>$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 such >> as this would be of help. >> >> As for who would implement it, that would be me. >> > I like it. Would like to see it be a bit more generic though, something > like (ignore the name, I can't name functions): > > array_validate_keys($array, is_int); > > I say this because it allows for more potential uses (that and I've done > exactly the same to check all keys are strings before). > > - Matt. > > --94eb2c06151e460038052b547e32--