Iterating Through Object Properties : foreach « Statement « PHP
- PHP
- Statement
- foreach
Iterating Through Object Properties
<?
class Person {
public $FirstName = "B";
public $MiddleName = "T";
public $LastName = "M";
private $Password = "asdfasdf";
public $Age = 29;
public $HomeTown = "Edinburgh";
public $FavouriteColor = "Purple";
}
$bill = new Person( );
foreach($bill as $var => $value) {
echo "$var is $value\n";
}
?>
Related examples in the same category