Skip to content
Browse files

Problem 4 complete.

  • Loading branch information...
1 parent 7240785 commit b1373c62b4275cbaff76ac870d31ed39d6add6f9 @benjaminfisher committed May 8, 2012
Showing with 31 additions and 0 deletions.
  1. +31 −0 midterm/prob4.php
View
31 midterm/prob4.php
@@ -7,6 +7,37 @@
include '_header.php';
+// Create and array of people with corresponding ages
+$people_ages = array(
+ 'Bob' => 50,
+ 'Bill' => 20,
+ 'Mary' => 3,
+ 'Lestat' => 5560,
+ 'Louie' => 523,
+ 'Chris' => 13,
+ 'Xander' => 37,
+ 'Benjamin' => 39,
+);
+
+// Output the array in unordered list sorted by name
+ksort($people_ages);
+echo "<h2>People I know sorted by name</h2>";
+echo "<ul>";
+foreach ($people_ages as $name => $age) {
+ echo "<li>$name is $age years old.";
+}
+echo "</ul>";
+
+// Output the array in a list sorted by age
+asort($people_ages);
+
+echo "<h2>People I know sorted by age</h2>";
+echo "<ul>";
+foreach ($people_ages as $name => $age) {
+ echo "<li>$name is $age years old.";
+}
+echo "</ul>";
+
?>

0 comments on commit b1373c6

Please sign in to comment.
Something went wrong with that request. Please try again.