What is Object Iteration in PHP?

Posted by Editorial Staff | Updated on

PHP 5 provides a way for objects to be defined so it is possible to iterate through a list of items, with, for example a foreach statement. By default, all visible properties will be used for the iteration.

Example #1 Simple Object Iteration

The above example will output:

The example code given for valid() will break if the array contains a FALSE value. This code prints out a single “bool(true)” and exits the loop when it gets to the FALSE:

Reference: https://www.php.net/manual/en/language.oop5.iterations.php


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers