Tuesday, April 11, 2017

My function won't store the highest value in the variable in Laravel

I'm trying to get this field from my Mongodb, but I don't know why I get stored in my var only the first value (that isn't the highest) and the correct one.

 public function globalChartGet() {
  $firstInChart = 0;
  $users = User::all();
  foreach ($users as $user) {
      if ($user->points > $firstInChart) {
        $firstInChart = $user->points;
    }
  }
 }



via McMazalf

Advertisement