Assignment 2 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Assignment 2.php

  1. <?php
  2. //Scott Walker 5/4/2022
  3. //Assignment 2 - Create a contact database with name and age, then sort by name and print to screen
  4.  
  5. echo "This is an aphabetically sorted array:";
  6.  
  7. $database1 = array("William" => 35,
  8. "Nina" => 56,
  9. "Ted" => 73,
  10. "Michael" => 22,
  11. "Michelle" => 62
  12. );
  13.  
  14. ksort($database1); //sorts the data in aphabetical order
  15.  
  16. //Print the headers of the Table
  17. echo "<table border='1' cellpadding='5'>";
  18. echo "<tr><th>Name</th><th>Age</th></tr>";
  19.  
  20. foreach($database1 as $Name=>$Age)
  21. {
  22. echo "<tr><td>$Name</td><td>$Age</td></tr>"; //Printes values into table cell
  23. }
  24. //Close the table
  25. echo "</table>";
  26. ?>
  27.  
  28.  
File Description
  • Assignment 2
  • PHP Code
  • 04 May-2022
  • 614 Bytes
You can Share it: