Skip to content

Instantly share code, notes, and snippets.

@makzan
Created September 1, 2018 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makzan/35b87a03004603d5c681087552ecdbde to your computer and use it in GitHub Desktop.
Save makzan/35b87a03004603d5c681087552ecdbde to your computer and use it in GitHub Desktop.
Example code for PHP class
<?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