Guest User

Untitled

a guest
Apr 25th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. $studentName = array('Sam Smith'=> array('Male' => 1), 'Gemma Francis'=> array('Female' => 2), 'Tom Jardine'=> array('Male' => 3), 'Callum Ralph'=> array('Male' => 3), 'Tim Baker'=> array('Male' => 4), 'Matt Bowes'=> array ('Male' => 2), 'Andy Brown'=> array ('Male' => 2), 'Peter Greene' => array ('Male' => 2), 'Emily Smith' => array ('Female' => 2));
  4.  
  5. echo '<table border="1">';
  6. echo '<tr>';
  7. echo '<th>Name</th>';
  8. echo '<th>Gender</th>';
  9. echo '<th>Year of Study</th>';
  10. echo '</tr>';
  11.  
  12. foreach ($studentName as $studentName => $studentGender){
  13.  
  14.     foreach ($studentGender as $studentGender => $yearOfStudy){
  15.  
  16.         if ($studentGender == 'Male' && $yearOfStudy == 2){
  17.  
  18.             echo '<td>';
  19.             echo $studentName.'</br>';
  20.             echo '</td>';
  21.  
  22.             echo '<td>';
  23.             echo $studentGender.'</br>';
  24.             echo '</td>';
  25.  
  26.             echo '<td>';
  27.             echo $yearOfStudy.'</br>';
  28.             echo '</td>';
  29.             echo '</tr>';
  30.  
  31.         }
  32.                
  33.     }
  34.    
  35. }
  36.  
  37. echo '</table>';
Add Comment
Please, Sign In to add comment