Re: Feature request - allow to append multiple elements to an array

From: Date: Mon, 30 Mar 2020 07:57:51 +0000
Subject: Re: Feature request - allow to append multiple elements to an array
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-109445@lists.php.net to get a copy of this message
On Sun, Mar 29, 2020 at 12:07 AM Michael Voříšek - ČVUT FEL < vorismi3@fel.cvut.cz> wrote: > Hi all PHP gurus! > > This is a feature request / RFC for the following use-case: > > $res = []; > foreach ($arr as $i) { > foreach (make_res($i) as $v) { > $res[] = $v; > } > } > > Array_merge in loop is very sloop so it is not a solution. > > which I propose to shorten to: > > $res = []; > foreach ($arr as $i) { > $res[...] = make_res($i); > } > > Appending multiple elements to an array is very common use-case. > > With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem, > > Michael Voříšek Not opposed to this on principle, but I don't like any of the syntax suggestions made yet. They all seem very ad-hoc and don't fit into any larger picture. The suggestion to use array_push($res, ...$elems) is the only one that makes sense syntactically, and it happens to already work. Nikita

« previous php.internals (#109445) next »