Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104812 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71895 invoked from network); 20 Mar 2019 03:18:21 -0000 Received: from unknown (HELO mail-ot1-f45.google.com) (209.85.210.45) by pb1.pair.com with SMTP; 20 Mar 2019 03:18:21 -0000 Received: by mail-ot1-f45.google.com with SMTP id q24so555327otk.0 for ; Tue, 19 Mar 2019 17:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FRUwMo1uA2EERQdF1Gdrc6pK5272bJg1zjkr6TrNxzs=; b=NW4DslbGmFqPu97aTWRFyDF8wkHryoC5tm9HW9LJf5bGL4dMg/CL1CPoqgzPadE8ze GI8TMnaE6RFtCDRjiGOtVmraP4BmpC+X61w90YE3L5/IwmYlFHOdEB9FNMQ5aiek/d2T dbibTjeL7j3z7Je68jbiqTNtS9D5EUHIQvOtQLH/ya58GwP6BNgVE0U7HbS0GEc7mnV0 ZGgGMWRwTvQ1aCRn1EpnJT08QuDQvmo42DY89x5Gw4qESNcA5bBrMX5NR5mGOOYTNXfN 5HzYFywiVDBvZ3FTYhGWsDi4dWWs3I0sLSDzt6VSh2Xs4DTt9tEnOgAQfyIxQr3mzGGC PAUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FRUwMo1uA2EERQdF1Gdrc6pK5272bJg1zjkr6TrNxzs=; b=hvGAnfh5Jyc3GQW97EX5fOQNR5iEmf4OSrA1ot7OdF1mOlaPHJIisoUGaR7e5wL9GM BSNW+knDgDUZHLCeOqk/XImafPmnfxo53gpHu55z6LU9yxrGLFeDgYg4eNItv1PEMSYp mE2fFAbOeV4QD1tuSnaaRiv4BwX1obCl0Q06LvlbgDh0T9Zv3q6jEU+akl/kSjAWqW/P 6j6iS/+VfPJRQwlNUxKFBm+nEqwW8d8hF1VuA/QqS8NYiXaF/vfnUyXENzEmEzDNcfeF osJsmupdPTT/CEPIazpQ5q0ff9nlqNUs3p2UdgG4Ek4x9ImVAZssGC2iXWrzSS1sUO7A ACDA== X-Gm-Message-State: APjAAAXNEsLW9Ts6oqxUpPdv7Hejt91pnnPk2oUsn37oLceUz3aPBqqo POfQFfNOXyai9ZUr48GAEBlnfAiQeZyY/Z4nlBQ= X-Google-Smtp-Source: APXvYqxIeg1u38CMdPxvGAhMMqCelmz1RCzr13vGxZhwwGR+VZhnOLMxPcht1RGoic8GtaLuO0uBowKPWx4xO4XwI7M= X-Received: by 2002:a9d:2944:: with SMTP id d62mr3811410otb.193.1553040606905; Tue, 19 Mar 2019 17:10:06 -0700 (PDT) MIME-Version: 1.0 References: <85417a73-a391-c9ad-49aa-5b88c65b0900@gmail.com> <5c8ea43d.1c69fb81.e50f1.7d18SMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: Date: Wed, 20 Mar 2019 00:09:54 +0000 Message-ID: To: Stanislav Malyshev Cc: Andrea Faulds , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] RFC Draft: Comprehensions From: robehickman@gmail.com (Robert Hickman) > > Why not apply the same approach to PHP? There is iterator_to_array() to > > convert a generator to an array, so we may not need both syntaxes. > > However, I think using [] for something that is *not an array* is > > counter-intuitive. > > No, I would definitely be for []-syntax producing an array. As I said, > that's in my experience what people usually want. > In python comprehensions on [] makes a list and comprehensions in {} make a dictionary (list and dict comprehensions). As PHP only has one 'array' type using [] makes sense. Along that train of thought, should comprehensions also be possible in the old array() syntax? Does the proposal include comprehensions which build associative arrays? In python you can do {a['key'] : a for a in lst}, where lst is a list of dicts. I often use this to create a dictionary whose keys index a sub-element of a nested dictionary, as my example shows.