How does PHP ‘foreach’ actually work?

foreach supports iteration over three different kinds of values: Arrays Normal objects Traversable objects In the following, I will try to explain precisely how iteration works in different cases. By far the simplest case is Traversable objects, as for these foreach is essentially only syntax sugar for code along these lines: foreach ($it as $k … Read more