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

From: Date: Sat, 28 Mar 2020 23:57:34 +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-109408@lists.php.net to get a copy of this message
Hi Michael, why not simply use array_push with multiple arguments? Something like: $a = []; array_push($a, ...array_fill(0, 10, 'x')); echo print_r($a, true); Cheers, Enno Am 29.03.2020 um 00:07 schrieb Michael Voříšek - ČVUT FEL:
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


« previous php.internals (#109408) next »