도움이 필요합니다. 나는 노동 계급이 있고 나는 공용 변수 표시) foreach 문을 (사용할 수 있습니다php foreach() 클래스 배열로
class MyClass {
public $a;
public $b;
function __construct($aX,$bX){
$this->a = $aX;
$this->b = $bX;
}
}
$class = new MyClass(3,5);
foreach($class as $key => $value) {
print "$key => $value</br>\n";
}
가 생산 : 나는 MyClass의 배열을 할 때
이a => 3
b => 5
이제 내 문제가 발생 :
를class MyClass
{
public $a;
public $b;
function __construct($aX,$bX){
$this->a = $aX;
$this->b = $bX;
}
}
$class = array(
"odd"=>new MyClass(3,5),
"even"=>new MyClass(2,4)
);
foreach($class as $key => $value) {
print "$key => $value</br>\n";
}
는 생산 :
Catchable fatal error: Object of class MyClass could not be converted to string...
$ class 배열의 모든 요소를 반복하는 방법은 무엇입니까? 어떤 도움이라도 좋을 것입니다!