I need to access a variable in a loop outside the for a loop.
I have defined the variable outside the class function as a private variable like this.
private $counter;
Then inside the function, I have used it like this.
public function counter_loop(){
for($i=0;$i<100;$i++){
$this->counter++;
}
return $this->counter;
}
But getting an error saying $counter is undefined.