lundi 9 mars 2020

Access variable outside for loop in Laravel

I need to access variable in a for loop outside the for 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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire