public static function eachReference(& $list, callable $iterator, $context = null)
    {
        if ($list === null)
            return $list;

        static::associate($iterator, $context);

        if (!static::isTraversable($list))
            throw new \InvalidArgumentException("canot iterate over " . static::typeOf($list));

        if ($list instanceof \Iterator)
            throw new \UnexpectedValueException("cannot iterate over an iterator by reference");

        foreach ($list as $index => & $item)
            if ($iterator($item, $index, $list) === static::BREAKER)
                break;

        return $list;
    }
public static function eachReference(& $list, callable $iterator, $context = null)
    {
        if ($list === null)
            return $list;

        static::associate($iterator, $context);

        if (!static::isTraversable($list))
            throw new \InvalidArgumentException("canot iterate over " . static::typeOf($list));

        if ($list instanceof \Iterator)
            throw new \UnexpectedValueException("cannot iterate over an iterator by reference");

        foreach ($list as $index => & $item)
            if ($iterator($item, $index, $list) === static::BREAKER)
                break;

        return $list;
    }
public static function eachReference ( & $ list , callable $ iterator , $ context = null ) { if ( $ list === null ) return $ list ; static :: associate ( $ iterator , $ context ) ; if ( ! static :: isTraversable ( $ list ) ) throw new \ InvalidArgumentException ( "canot iterate over " . static :: typeOf ( $ list ) ) ; if ( $ list instanceof \ Iterator ) throw new \ UnexpectedValueException ( "cannot iterate over an iterator by reference" ) ; foreach ( $ list as $ index => & $ item ) if ( $ iterator ( $ item , $ index , $ list ) === static :: BREAKER ) break ; return $ list ; }
Does the very same job as each but provide a reference of every list item to the iterator function.

@category Collection Functions

@param traversable $list the list to iterate over
@param callable $iterator the iteration function
@param object $context optional, if provided will become the context of $iterator

@throws InvalidArgumentException if $list cannot be iterated over
@throws UnexpectedValueException if $list is an instance of Iterator

@return void
Does the very same job as each but provide a reference of every list item to the iterator function .