Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

jamesjones21
jamesjones21
9,260 Points

Schools out practice

1 Add more grade levels. 2 Create an associative array of grade number and name. Then use that array to write out the message instead. 3 Add Teachers and sign the message. Try both the current grade and next grade. 4 Make an array of students to loop through.

In these 4 steps would I create an array with a students name and his / her grade? Then run a comparison to determine which have passed and those who has t ?

Really confused, or would it be 3 seperate arrays ?

Cheers

1 Answer

jamesjones21
jamesjones21
9,260 Points

worked it out by using a foreach loop and then setting $key and $values as variables

<?php

$scorePass = 10;
$student[] = array(

'Name' => 'James',  
'Score' => 11,
'Next Grade' => 16,
  );

$student[] = array(

'Name' => 'Laura',  
'Score' => 12,
'Next Grade' => 16,
  );

$student[] = array(

'Name' => 'Rebecca',  
'Score' => 15,
'Next Grade' => 16,
  );

$student[] = array(

'Name' => 'Judith',  
'Score' => 9,
'Next Grade' => 16,
  );

$student[] = array(

'Name' => 'Jean',  
'Score' => 8,
'Next Grade' => 16,
  );

foreach ($student as $key => $value) {
  if ($value['Score'] >= $scorePass){
    echo $value['Name'] . " has passed. " ."Your score was: <br />\n" . $value['Score'] . "<br />\n";
  } else {
    echo $value['Name'] . " you need a higher score." . "Your score was: <br />\n " . $value['Score'] . "<br />\n";
  }
}


?>