On Fri, Jun 2, 2017 at 11:12 AM, Michael Morris <tendo...@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);
        }
    }

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to