Relative Content

Tag Archive for phparrays

How does the ‘as’ syntax work in foreach?

I am struggling with how the ‘as’ works in arrays. Also a bit confused on the breakup of the $name and $grade. Thanks $studentGrades = [ ‘John’ => 90, ‘Mary’ => 94, ‘Cindy’ => 80 ]; foreach($studentGrades as $name => $grade) { if($grade >= 90) { echo $name . ‘You have an A <br>’; } […]