Page 165 - Beginning PHP 5.3
P. 165
Chapter 6: Arrays
You can see that array_multisort() has sorted the $myBooks array by title. What if you wanted to
sort by author, then by publication year, then by title? In that case you need to change the order of the
elements in the nested associative arrays:
$myBooks = array(
array(
“author” = > “John Steinbeck”,
“pubYear” = > 1939,
“title” = > “The Grapes of Wrath”
),
array(
“author” = > “John Steinbeck”,
“pubYear” = > 1962,
“title” = > “Travels With Charley”
),
array(
“author” = > “Franz Kafka”,
“pubYear” = > 1925,
“title” = > “The Trial”
),
array(
“author” = > “J. R. R. Tolkien”,
“pubYear” = > 1937,
“title” = > “The Hobbit”
),
array(
“author” = > “Charles Dickens”,
“pubYear” = > 1859,
“title” = > “A Tale of Two Cities”
),
);
Running array_multisort() on this array produces the result shown in Figure 6-7 .
127
9/21/09 9:00:18 AM
c06.indd 127
c06.indd 127 9/21/09 9:00:18 AM