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! Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
AviNahum Posted May 13, 2010 Author Share Posted May 13, 2010 works great! Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.