Re: Feature request - allow to append multiple elements to an array
| From: | Manuel Canga | Date: | Sun, 29 Mar 2020 19:05:05 +0000 |
| Subject: | Re: Feature request - allow to append multiple elements to an array | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109417@lists.php.net to get a copy of this message | ||
Hi, Internals
>
> Em sáb., 28 de mar. de 2020 às 20:07, Michael Voříšek - ČVUT FEL <
> vorismi3@fel.cvut.cz> escreveu:
>
> > 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;
> > }
> > }
> >
Maybe, PHP needs array_flatten like Ruby:
https://apidock.com/ruby/Array/flatten
In this way, above code would be equal to:
$res = array_flatten( array_map('make_res', $arr) );
Regards
--
Manuel Canga