note 18329 added to control-structures.foreach

From: Date: Fri, 18 Jan 2002 15:02:18 +0000
Subject: note 18329 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-25042@lists.php.net to get a copy of this message
I've just discovered that 'foreach' allows you to loop through / enumerate the properties of (copies of) objects as well as arrays... <?php class person { var $firstName = "Joe"; var $lastName = "Bloggs"; var $age = "25"; } $person = new person; foreach ($person as $key=>$val) { echo "$key = $val\n"; } /* Prints... firstName = Joe lastName = Bloggs age = 25 */ ?> ...why didn't anyone tell me about this before? :) -- http://www.php.net/manual/en/control-structures.foreach.php http://master.php.net/manage/user-notes.php?action=edit+18329 http://master.php.net/manage/user-notes.php?action=delete+18329 http://master.php.net/manage/user-notes.php?action=reject+18329

« previous php.notes (#25042) next »