Developing software in the Real World

The internal pointer of an array

I discovered recently that if you walk through an array using array_walk or array_walk_recursive, then the array’s internal pointer is left at the end of the array. Clearly this isn’t something that I’ve needed to know before!

This code example shows the fundamentals:

The output is NULL and you use reset() to put the internal pointed back to the start.

Foreach is different in PHP 7!

Note that foreach works the same way in PHP 5, but works differently in PHP 7:

will output string(1) "a" on PHP 7 and NULL on PHP 5.

3 thoughts on “The internal pointer of an array

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *