hey, jason, question for you
Moderator: General Moderators
hey, jason, question for you
hey, jason, how could I have something be sortable by (...oh say) natural numerical order [natsort()] and in descending order? I noticed you did this on the member list, so thanks.
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
i know this wasn't directed at me but you might want to look into
array_reverse()
http://www.php.net/array_reverse
you could sort them, put them in an array and then reverse them..
array_reverse()
http://www.php.net/array_reverse
you could sort them, put them in an array and then reverse them..
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Using array_reverse - if the array to be sorted was $array:
All that array_reverse does is reverse the order of the elements in the array.
Mac
Code: Select all
<?php
// Sort in ascending order
$array_up = natsort($array);
// Sort in descending order
$array_down = array_reverse(natsort($array));
?>Mac
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
you could have some links at the bottom like..
and assuming the results were $array ... you could have
to descide whether to ascend or descend...
Code: Select all
<a href="<?=$PHP_SELF;?>?op=asc">Ascending!</a><br />
<a href="<?=$PHP_SELF;?>?op=des">Descending!</a><br />Code: Select all
<?php
if($op == "asc"){
$sorted_array = natsort($array);
}
if($op == "des"){
$sorted_array = array_reverse(natsort($array));
} else {
$sorted_array = natsort($array);
//making ascending default..
}
$a_c = count($sorted_array);
echo "<table><tr><td><b>Widths</b></td></tr>
for($i = 0; $i <= $a_c; $i++){
echo "<tr><td>".$sorted_arrayї$i]."</td></tr>\n"
}
?>