AviNahum Posted May 13, 2010 Share Posted May 13, 2010 i'm trying to create a function thats sorts 4 images from the highest one to the shortest one... // array of my images $images = array($proj['image1'], $proj['image2'], $proj['image3'], $proj['image4']); $sorted = array(0, 0, 0, 0); // put all heights in array for ($i=0; $i<4; $i++) { list($width, $height, $type, $attr) = getimagesize("admin/images/projects/".$images[$i]); $sorted[$i] = $height; } // sort it from the bigest number to the lowest rsort($sorted); // this gonna contain the sorted images $si = array(); for ($i=0; $i<4; $i++) { list($width, $height, $type, $attr) = getimagesize("admin/images/projects/".$images[$i]); for ($j=0; $j<4; $j++) { if ($sorted[$j] == $height) $si[$j] = $images[$i]; } } but if there two images with the same height, it's repeat this images few times... any ideas? Thanks! Link to comment https://forums.phpfreaks.com/topic/201631-sort-images-from-the-highest-to-the-shortest/ Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 You're over-thinking this. Try: <?php $images = array($proj['image1'], $proj['image2'], $proj['image3'], $proj['image4']); $sorted = array(); foreach($images as $img) { list($width, $height, $type, $attr) = getimagesize("admin/images/projects/".$images[$i]); $sorted[$img] = $height; } arsort($sorted); echo '<pre>' . print_r($sorted,true) . '</pre>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/201631-sort-images-from-the-highest-to-the-shortest/#findComment-1057724 Share on other sites More sharing options...
AviNahum Posted May 13, 2010 Author Share Posted May 13, 2010 works great! Thank you! Link to comment https://forums.phpfreaks.com/topic/201631-sort-images-from-the-highest-to-the-shortest/#findComment-1057755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.