Reputation: 429
There is one class:
Class A {
public function Q(){
return value;
}
}
In loop I create some exemplars of class A:
while ($i < 5){
$obj_$i = new A();
$obj_$i->Q();
}
Where can I save all results of $obj_$i->Q();
for each iteration on loop?
Because I after I need to trasfer these objects in another class to handling.
Class B {
public function Result(){
return $obj_$i + 3;
}
}
Upvotes: 1
Views: 125
Reputation: 16963
Create an array and push the objects to this array in each iteration of while()
loop, like this:
$objArray = array();
while ($i < 5){
$objArray[] = new A();
}
Later, pass this array to Result()
method of class B
for further processing,
class B {
public function Result($objArray){
foreach($objArray as $obj){
// your code
}
}
}
Upvotes: 1