Forum Moderators: coopster
$data[] = array('volume' => 67, 'edition' => 2, 'test' => 1);
$data[] = array('volume' => 86, 'edition' => 1, 'test' => 9);
$data[] = array('volume' => 85, 'edition' => 6, 'test' => 11);
$data[] = array('volume' => 98, 'edition' => 2, 'test' => 23);
$data[] = array('volume' => 86, 'edition' => 6, 'test' => 35);
$data[] = array('volume' => 67, 'edition' => 7, 'test' => 13);foreach ($data as $key => $row) {
$volume[$key] = $row['volume'];
$edition[$key] = $row['edition'];
$test[$key] = $row['test'];
}
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
This gives me my array and will sort it but now I'd like to echo the results like this
echo $row['volume']." ¦ ".$row['edition']." ¦ ".$row['test']."<br />";
How do I loop that so I see all the information? Normally I'd use while with database results... will that work here as well?
foreach ($data as $key => $row) {
echo $row['volume']." ¦ ".$row['edition']." ¦ ".$row['test']."<br />";
}
Final thing and then I'm done... I know I said that last time. :-)
while ($row_playerlist = mysql_fetch_assoc($playerlist)){
$playerid = $row_playerlist['playerid'];
$firstname = $row_playerlist['firstname'];
$lastname = $row_playerlist['lastname'];
$player[] = array('playerid' => $playerid, 'firstname' => $firstname, 'lastname' => $lastname);
}foreach ($player as $key => $row) {
$playerid[$key] = $row['playerid'];
$firstname[$key] = $row['firstname'];
$lastname[$key] = $row['lastname'];
}
array_multisort($firstname, SORT_ASC, $lastname, SORT_ASC, $player);$count = 0;
foreach ($player as $key => $row) {
echo $row['playerid']." ¦ ".$row['firstname']." ¦ ".$row['lastname']."<br />\n";
if (++$count == 3) { break; }
}
For some reason I'm getting this error message:
Warning: array_multisort(): Argument #1 is expected to be an array or a sort flag in blah blah blah on line 19
It worked before, but for some reason not now?
[edited by: coopster at 6:43 pm (utc) on May 10, 2006]
[edit reason] fixed sidescroll [/edit]
while ($row_playerlist = mysql_fetch_assoc($playerlist)){
$playerid = $row_playerlist['playerid'];
$firstname = $row_playerlist['firstname'];
$lastname = $row_playerlist['lastname'];
$player[] = array('playerid' => $playerid, 'firstname' => $firstname, 'lastname' => $lastname);
}
$playerid = array();
$firstname = array();
$lastname = array();
foreach ($player as $key => $row) {
$playerid[$key] = $row['playerid'];
$firstname[$key] = $row['firstname'];
$lastname[$key] = $row['lastname'];
}
array_multisort($firstname, SORT_ASC, $lastname, SORT_ASC, $player);
$firstname = 'mooger';
print "$firstname<br />"; //
$firstname[0] = 'M';
$firstname[1] = 'O';
$firstname[2] = 'O';
print "$firstname<br />";
// will output:
mooger
MOOger