Re: RFC proposal
| From: | Levi Morrison | Date: | Fri, 02 Jun 2017 17:21:34 +0000 |
| Subject: | Re: RFC proposal | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-99327@lists.php.net to get a copy of this message | ||
On Fri, Jun 2, 2017 at 11:12 AM, Michael Morris <tendoaki@gmail.com> wrote:
> What about foreach by reference, which is honestly the only time I use
> referencing anymore...
>
> foreach ($array as $key => &$value) {
> $value = someOp($value);
> }
>
> Is this also bad?
I'm not going to say "bad" but I would not personally write it that
way. If the memory cost is too high to duplicate then I'd use a
generator that maps the value; I have this function in all my projects
because it's fairly common anyway:
function (callable $fn, iterable $input) {
foreach ($input as $key => $value) {
yield $iey => $fn($value);
}
}