i trying show images on website php usort, new images should @ top , oldest @ bottom. tried use usort, not working , images still displayed opposite way, old ones @ top , new ones @ bottom. wrong code, or why happening? (i read of topics here @ stackoverflow have in common, did not figured out wrong.)
i use code:
$folder_path = 'posters/'; $num_files = glob($folder_path . "*.{jpg,jpg,gif,png,bmp}", glob_brace); usort( $num_files, function( $a, $b ) { return filemtime($a) < filemtime($b); } ); $folder = opendir($folder_path);
the comparison function must return integer less than, equal to, or greater 0 if first argument considered respectively less than, equal to, or greater second.
you're returning boolean (true/false). try swapping <
-
. , if reverse of should have, swap $a
$b
, should order right way.
Comments
Post a Comment