如何循环Class
的所有属性class object {
public $a = 1;
public $b = 2;
public $c = 3;
}
,输出将是
"property $a is 1";
"property $b is 2";
"property $c is 3";
答案 0 :(得分:5)
foreach (new object as $prop => $value) {
echo "property \$$prop is $value\n";
}
答案 1 :(得分:2)
您可以查看get_object_vars()
,但在查看Polynomial的评论后不会看。