gpt4 book ai didi

php - 循环类属性

转载 作者:行者123 更新时间:2023-12-03 23:01:20 24 4
gpt4 key购买 nike

如何循环Class的所有属性

class object {
public $a = 1;
public $b = 2;
public $c = 3;
}

输出将是

"property $a is 1";
"property $b is 2";
"property $c is 3";

最佳答案

您可以 use a foreach loop :

foreach (new object as $prop => $value) {
echo "property \$$prop is $value\n";
}

关于php - 循环类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8048887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com