Herpicus
Web Developer
Edit Problem Solved Thanks to Holix on IRC
Solved:
Thread can be closed.
So heres my situation, my wallpapers site currently only supports sorting with ascending or descending. I would like my site to show the images randomly.
I've tried using shuffle() but I can't seem to get it to work.
Here is what I have:
Here is the original:
Any help is greatly appreciated!
Solved:
PHP:
function cmp($a, $b) {
global $CFG_sorting_order, $CFG_sorting_type;
if ($CFG_sorting_order == "ascending")
{
return strcasecmp($b['name'], $a['name']);
}
if ($CFG_sorting_order == "descending")
{
return strcasecmp($a['name'], $b['name']);
}
if ($CFG_sorting_order == "random")
{
return (mt_rand(0, 1) ? $a['name'] : $b['name']);
}
}
@usort($dirs_raw, 'cmp');
@usort($files_raw, 'cmp');
So heres my situation, my wallpapers site currently only supports sorting with ascending or descending. I would like my site to show the images randomly.
I've tried using shuffle() but I can't seem to get it to work.
Here is what I have:
PHP:
function cmp($a, $b) {
global $CFG_sorting_order, $CFG_sorting_type;
if ($CFG_sorting_order == "ascending")
{
return strcasecmp($b['name'], $a['name']);
}
if ($CFG_sorting_order == "descending")
{
return strcasecmp($a['name'], $b['name']);
}
if ($CFG_sorting_order == "random")
{
return shuffle($a['name'], $b['name']);
}
}
@usort($dirs_raw, 'cmp');
@usort($files_raw, 'cmp');
Here is the original:
PHP:
function cmp($a, $b) {
global $CFG_sorting_order, $CFG_sorting_type;
if ($CFG_sorting_order == "ascending")
{
return strcasecmp($b['name'], $a['name']);
}
if ($CFG_sorting_order == "descending")
{
return strcasecmp($a['name'], $b['name']);
}
} // function cmp
@usort($dirs_raw, 'cmp');
@usort($files_raw, 'cmp');
Any help is greatly appreciated!
Last edited: