Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91112 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54153 invoked from network); 8 Feb 2016 15:00:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2016 15:00:06 -0000 Received: from [127.0.0.1] ([127.0.0.1:19360]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 9C/D1-36326-57DA8B65 for ; Mon, 08 Feb 2016 10:00:05 -0500 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.213.178 cause and error) X-PHP-List-Original-Sender: matthew@maltblue.com X-Host-Fingerprint: 209.85.213.178 mail-ig0-f178.google.com Received: from [209.85.213.178] ([209.85.213.178:37606] helo=mail-ig0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D4/D1-36326-BF6A8B65 for ; Mon, 08 Feb 2016 09:32:28 -0500 Received: by mail-ig0-f178.google.com with SMTP id 5so58863771igt.0 for ; Mon, 08 Feb 2016 06:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maltblue-com.20150623.gappssmtp.com; s=20150623; h=mime-version:date:message-id:subject:from:to:content-type; bh=dinAYDK6OvfPHLKV+wcqBMH+Zq5A6tFqoV6vpZw1hxg=; b=R+yTGPcyDgV2trEgTYQBxnZDFaqP/p8S3C0kSWiUGpJSKC9O8uuSfWs0FV/QIK+PL+ DRFo0k1Ue+1X2qFN+Y5ZoGAFEfDmdJ0PIfPxaHo8tM0q0eOG661C3XJd1dY8C4tw1WzK gwlDElvwE+iW1IAmb/YT+3Vwf40Mvz91YcsddUJXZw2gd2jHtgQS1kV4IGPmp5Za5deg CpUEVtHw+nnDfqwEiCw55dq5NUd+siNEa0QeEKfHfkb2J6+WhJ6Za2yhdmtJ2eufJp5/ qrS8INjgN0BKOFdvecP7ktUHwLLTP4W9H1lAsUKqxVYn1q2PwWGbNHl00Etsljocadf+ 9i8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=dinAYDK6OvfPHLKV+wcqBMH+Zq5A6tFqoV6vpZw1hxg=; b=fT8PzOM/vJQpPbWOtrrdVsEE9q0rpCFR3fQ1xoX1HifLspfA5cR9joOe3FF5S2Rx4z cYFJAWxxO1PNfwxMctGmFXsgKnifrWz1oFpsr0hPOWWqkdN7DscS7klY3L+2JJAzDxF8 jkjZwxo8o8vh8eBSFFX8jSi2rjKnnWJp9LWFiyKZUV+ZOEQH+oOv5qPW+uUSJlpNMv49 ++soou1vJ86GdCpiw/KRvC4IrUqhEBXZJWPj/MxjPgHpUaBHEp4vRRi/Tbdq8pHF0E6D 4i14oUhY847bG5+vPnV2wG6BzuXjH0uiSfxxPpcdIV/btEnoaos3DwD/saYs8Ejkng8R Z0lg== X-Gm-Message-State: AG10YOQdm8wepC5gcC9Zs3ah3U3ZGFOMSIoVhxPf9q1oD468FvbdRl7dlp3xd34s/4AL0v8zVifQBHp3N7S0ww== MIME-Version: 1.0 X-Received: by 10.50.79.130 with SMTP id j2mr22953172igx.25.1454941945386; Mon, 08 Feb 2016 06:32:25 -0800 (PST) Received: by 10.79.4.195 with HTTP; Mon, 8 Feb 2016 06:32:25 -0800 (PST) X-Originating-IP: [188.99.33.229] Date: Mon, 8 Feb 2016 15:32:25 +0100 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=089e0112d074d2f7ed052b431132 Subject: Proposal for a new array function From: matthew@maltblue.com (Matthew Setter) --089e0112d074d2f7ed052b431132 Content-Type: text/plain; charset=UTF-8 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. -- 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 * --089e0112d074d2f7ed052b431132--