Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67653 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99438 invoked from network); 8 Jun 2013 07:14:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jun 2013 07:14:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierre@pcservice.co.za; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pierre@pcservice.co.za; sender-id=pass Received-SPF: pass (pb1.pair.com: domain pcservice.co.za designates 69.93.82.2 as permitted sender) X-PHP-List-Original-Sender: pierre@pcservice.co.za X-Host-Fingerprint: 69.93.82.2 gateway14.websitewelcome.com Linux 2.6 Received: from [69.93.82.2] ([69.93.82.2:37581] helo=gateway14.websitewelcome.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6E/11-25405-0D9D2B15 for ; Sat, 08 Jun 2013 03:14:26 -0400 Received: by gateway14.websitewelcome.com (Postfix, from userid 5007) id 108A248F1F2E8; Sat, 8 Jun 2013 02:14:17 -0500 (CDT) Received: from vinacomin.websitewelcome.com (vinacomin.websitewelcome.com [50.97.101.199]) by gateway14.websitewelcome.com (Postfix) with ESMTP id 01ACD48F1F2C4 for ; Sat, 8 Jun 2013 02:14:17 -0500 (CDT) Received: from [209.85.128.47] (port=59158 helo=mail-qe0-f47.google.com) by vinacomin.websitewelcome.com with esmtpsa (TLSv1:RC4-SHA:128) (Exim 4.80) (envelope-from ) id 1UlDLx-0002BB-RU for internals@lists.php.net; Sat, 08 Jun 2013 02:14:21 -0500 Received: by mail-qe0-f47.google.com with SMTP id 1so3248180qec.34 for ; Sat, 08 Jun 2013 00:14:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=aMPy2aik+YDgjfvHxY+d0fPWoVuaAPsOtS00QxwIf2Y=; b=fdgfTBkA5yxA1JFXfrhTOX2KWVTxPryglNQBG2esd7Uq7JUgSLkw6NgKzgCfkG8Rhy ghwPPmw9WO17+UP9g8wXzU4AFsk4KvhfmZ0bV5vAmBRQ8CFX61OiYFfQMFomGeW1Y5lR gP8i1udLglf9kUksr2TyCu0zCMEEHPViJh6FClc1EsUSrAto6oJB7L93ZX+VUjEcgLFo qvTRFEVQnsJ4fOvkwcXt1HTSLB2R6TxEIuwWzUYcKaaTGUgW5GtuE5M0B0qlLpC8VF9A KW5umdRxFQwIN7g6/I26LttkVgW1kOSpdYJ/uB3aTGO0XbfEh+3yKIVCxwLZAgVCNPCB CxSQ== X-Received: by 10.229.106.162 with SMTP id x34mr765694qco.68.1370675661185; Sat, 08 Jun 2013 00:14:21 -0700 (PDT) MIME-Version: 1.0 Reply-To: pierre@pcservice.co.za Received: by 10.49.18.138 with HTTP; Sat, 8 Jun 2013 00:13:51 -0700 (PDT) In-Reply-To: References: Date: Sat, 8 Jun 2013 09:13:51 +0200 Message-ID: To: Sherif Ramadan Cc: PHP Internals Content-Type: multipart/alternative; boundary=0023543329e6e34e2f04de9f4b6b X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vinacomin.websitewelcome.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - pcservice.co.za X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (mail-qe0-f47.google.com) [209.85.128.47]:59158 X-Source-Auth: pierre@pcservice.co.za X-Email-Count: 1 X-Source-Cap: cGNzZXJ2aWM7cGllcnJlO3ZpbmFjb21pbi53ZWJzaXRld2VsY29tZS5jb20= Subject: Re: [PHP-DEV] Proposal for new array_map function to pass in keys From: pierre@pcservice.co.za (Pierre du Plessis) --0023543329e6e34e2f04de9f4b6b Content-Type: text/plain; charset=ISO-8859-1 > function my_call_back($key, $value) { > return array($value, strlen($value)); > } > $array = str_word_count("PHP is lots of fun!"); > $array = array_map_key('my_call_back', $array); > > > The result would be the following array: > > array(5) { > ["PHP"]=> > int(3) > ["is"]=> > int(2) > ["lots"]=> > int(4) > ["of"]=> > int(2) > ["fun"]=> > int(3) > } > > This example doesn't make any sense, as str_word_count returns an integer, so you would in fact pass an int to array_map_key and not an array. But let's say using your example, you use explode(" ", $string) instead of str_word_count, which will give you an array of all the words. What happens in the following case: function my_call_back($key, $value) { return array($value, strlen($value)); } $array = str_word_count("PHP stands for PHP hypertext preprocessor"); $array = array_map_key('my_call_back', $array); This would give you 2 keys with the value of PHP. What happens in this case? What if you have duplicate integer keys. Does the keys simply increment or throw an error? --0023543329e6e34e2f04de9f4b6b--