Created
September 1, 2018 07:48
-
-
Save makzan/35b87a03004603d5c681087552ecdbde to your computer and use it in GitHub Desktop.
Example code for PHP class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// DATA | |
$students = []; | |
$students[] = [ | |
"name" => "Thomas Mak", | |
"class" => "S1A", | |
"number" => 32, | |
"enrolled_classes" => [ | |
"Chinese", | |
"English", | |
"Web Develpment" | |
], | |
]; | |
$students[] = [ | |
"name" => "John Ivan", | |
"class" => "S1B", | |
"number" => 31, | |
"enrolled_classes" => [ | |
"Chinese", | |
"English", | |
"Web Develpment" | |
], | |
]; | |
$students[] = [ | |
"name" => "Susuan Lee", | |
"class" => "S1A", | |
"number" => 12, | |
"enrolled_classes" => [ | |
"English", | |
"Physics", | |
"Web Develpment" | |
], | |
]; | |
// echo "<pre>"; | |
// var_dump($students); | |
$class = $_POST["class"] ?? ""; | |
?> | |
<h1>Students</h1> | |
<ol> | |
<?php foreach($students as $student): ?> | |
<?php if ($student["class"] == $class): ?> | |
<li> | |
<strong><?= $student["name"] ?></strong> | |
<br> | |
<?= $student["class"] ?> <?=$student["number"] ?> | |
</li> | |
<?php endif; ?> | |
<?php endforeach ?> | |
</ol> | |
<form action="" method="POST"> | |
Please choose class to list students:<br> | |
<select name="class"> | |
<option value="S1A">高一信</option> | |
<option value="S1B">高一望</option> | |
</select> | |
<input type="submit" value="List Students"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment