Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Problem 4 complete.

  • Loading branch information...
commit b1373c62b4275cbaff76ac870d31ed39d6add6f9 1 parent 7240785
Benjamin J. Fisher authored

Showing 1 changed file with 31 additions and 0 deletions. Show diff stats Hide diff stats

  1. +31 0 midterm/prob4.php
31 midterm/prob4.php
@@ -7,6 +7,37 @@
7 7
8 8 include '_header.php';
9 9
  10 +// Create and array of people with corresponding ages
  11 +$people_ages = array(
  12 + 'Bob' => 50,
  13 + 'Bill' => 20,
  14 + 'Mary' => 3,
  15 + 'Lestat' => 5560,
  16 + 'Louie' => 523,
  17 + 'Chris' => 13,
  18 + 'Xander' => 37,
  19 + 'Benjamin' => 39,
  20 +);
  21 +
  22 +// Output the array in unordered list sorted by name
  23 +ksort($people_ages);
  24 +echo "<h2>People I know sorted by name</h2>";
  25 +echo "<ul>";
  26 +foreach ($people_ages as $name => $age) {
  27 + echo "<li>$name is $age years old.";
  28 +}
  29 +echo "</ul>";
  30 +
  31 +// Output the array in a list sorted by age
  32 +asort($people_ages);
  33 +
  34 +echo "<h2>People I know sorted by age</h2>";
  35 +echo "<ul>";
  36 +foreach ($people_ages as $name => $age) {
  37 + echo "<li>$name is $age years old.";
  38 +}
  39 +echo "</ul>";
  40 +
10 41 ?>
11 42
12 43

0 comments on commit b1373c6

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