Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91121 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71856 invoked from network); 8 Feb 2016 16:36:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2016 16:36:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.43 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.43 mail-wm0-f43.google.com Received: from [74.125.82.43] ([74.125.82.43:33051] helo=mail-wm0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F8/35-36326-3F3C8B65 for ; Mon, 08 Feb 2016 11:36:04 -0500 Received: by mail-wm0-f43.google.com with SMTP id g62so140439157wme.0 for ; Mon, 08 Feb 2016 08:36:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=/GVf3Qf13Crd5QWxvOROLQ6H4P/xatOXTA1LzC7bgIw=; b=MmrsCTV/HKAz87+SDEZj+oc9+fWBcaj6+tbY709xlP5r5gz++6I0hvkGlxFWXKmtKD 8TpEDBuDs8rP+CEcnuRfzygPAx4z3zLqRly+1EYwoAMl9kDikozZNj7DHBEvLb9/DFE0 5mUik6yvUEqPCN3bMUuoXOUmZsdr5A/DiZTueaUmeRE8RrhaEZUaBk7g/lAS4jYomugP OiDtMZnUQnqK4Iyal59CI/o/fRxM/XUPLDngE5UHSpEnGMA0O3f+xEyiwU8Gw8vN1Qki KIE/5nIFpXgwcVoprtKZnjhWT/QbindUaOyL+1Of4qVCUZnD96sz2XkB/umagwtN8Ioj 9CjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=/GVf3Qf13Crd5QWxvOROLQ6H4P/xatOXTA1LzC7bgIw=; b=Jb7SCxwAEpYhBYY+7zG8DFmSGl7zi9hHWiDk4/B7idFBOICYwdOrZcRaonQURIdS2E o64rXg5bnu1Ts2xUXuDPdLUF7RADtVy54EwYjqg7ZN38rAdCu98BLqeDgYAFPyscARnm Fy2JyaN/ovQNC3G9KXfV+t69sL0tfWMmRcG4M64vIUew/Fomc4U813BDy7eLCpf8FDD6 iAYfZQjyEqVjln31c59fLukyUyu4SwaGyc+qxUij536upjy395m+aNNvKGSUTVOhhR04 uOMnbNZBXAM+RieibLnBbFBhOu4g2IbNEscWlmsA9Ps64w0ZmwFpVvrmVLFDfCR+dJT0 XttQ== X-Gm-Message-State: AG10YOR+n7+NT04i7FIxxm3M+Cztk387W8ewXgZiOYCTsFMwvfGbs3FFm5ZwY3i0iwCVeg== X-Received: by 10.194.179.71 with SMTP id de7mr27980429wjc.119.1454949360463; Mon, 08 Feb 2016 08:36:00 -0800 (PST) Received: from [192.168.0.152] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id hm9sm30508122wjb.34.2016.02.08.08.35.59 for (version=TLSv1/SSLv3 cipher=OTHER); Mon, 08 Feb 2016 08:35:59 -0800 (PST) To: internals@lists.php.net References: <56B8B7C6.6000206@php.net> Message-ID: <56B8C39A.9070008@gmail.com> Date: Mon, 8 Feb 2016 16:34:34 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <56B8B7C6.6000206@php.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Proposal for a new array function From: rowan.collins@gmail.com (Rowan Collins) François Laupretre wrote on 08/02/2016 15:44: > For a better consistency, may I suggest a function that would allow to > know whether array keys are all numeric, all strings, or mixed. > Something like array_keys_type() returning one of 3 predefined > constants : ARRAY_KEYS_NUMERIC, ARRAY_KEYS_STRING, ARRAY_KEYS_MIXED. The problem with this is that it's significantly harder to optimise than cases where you are falsifying a single hypothesis: - if the question is "are all keys integers?", you can return false as soon as you find a string key - if the question is "are all keys strings?", you can return false as soon as you find an integer key - if the question is "does the array contain both types of key?", you can return false as soon as you have found one of each type of key Combining the functions allows the 3rd optimisation only, which is probably the least common use case. In the OP's use case, given a large array consisting only of string keys, the function would have to examine every key to decide whether to return ARRAY_KEYS_STRING or ARRAY_KEYS_MIXED, although the user doesn't care about that distinction. Regards, -- Rowan Collins [IMSoP]