Jump to content
Larry Ullman's Book Forums

nomadsoul

Members
  • Posts

    29
  • Joined

  • Last visited

Everything posted by nomadsoul

  1. I'm having trouble understanding how the array is being sorted. Specifically; each echo statement is the same so how does it know which function to echo? Thanks $students = array ( 256 => array ('name' => 'Jon', 'grade' => 98.5), 2 => array ('name' => 'Vance', 'grade' => 85.1), 9 => array ('name' => 'Stephen', 'grade' => 94.0), 364 => array ('name' => 'Steve', 'grade' => 85.1), 68 => array ('name' => 'Rob', 'grade' => 74.6) ); // Name sorting function: function name_sort ($x, $y) { return strcasecmp($x['name'], $y['name']); } // Grade sorting function: // Sort in DESCENDING order! function grade_sort ($x, $y) { return ($x['grade'] < $y['grade']); } // Print the array as is: echo '<h3>Array As Is</h3><pre>' . print_r($students, 1) . '</pre>'; // Sort by name: uasort ($students, 'name_sort'); // Print the array now: echo '<h3>Array Sorted By Name</h3><pre>' . print_r($students, 1) . '</pre>'; // Sort by grade: uasort ($students, 'grade_sort'); */ // Print the array now: echo '<h3>Array Sorted By Grade</h3><pre>' . print_r($students, 1) . '</pre>'; ?> </body> </html>
  2. Hi, In the script on page 5 line 40, in the print_r function's argument, what is the "1" for? echo '<h3>Array As Is</h3><pre>' . print_r($students, 1) . '</pre>'; thanks
  3. Hi Vince, I don't have this book yet, I am waiting for it to arrive. I am one of the lucky winners. But I did download the code. Hope your website plan is going well
×
×
  • Create New...