hsub Posted December 4, 2008 Share Posted December 4, 2008 hi all, i can't seem to figure out how to do this. below is a bit of code that sort through an array and return the 3 highest value. i would like to then take those three values and place them separately into the <div id> tags. <? $array = array(5, 8694, 13,5,46,84,9,48684,8642,54,3,664,87,93,24,56,487,9341,8432); rsort($array); for($i = 0; $i < 3; $i++) // Only loop 10 times. echo $array[$i] . "<br>"; ?> <div id="container"> <div id="left"> <?php echo $highest?></div> <div id="center"><?php echo $secondhighest; ?></div> <div id="right"><?php echo $thirdhighest; ?></div> </div> thank you in advance for any help on this. Quote Link to comment https://forums.phpfreaks.com/topic/135521-array-data-echo-into-table/ Share on other sites More sharing options...
Adam Posted December 4, 2008 Share Posted December 4, 2008 The three highest from that array after it's sorted will be: $array[0]; // highest $array[1]; // second highest $array[2]; // third highest I'd recommend not using an array named $array though, may run into troubles... Adam Quote Link to comment https://forums.phpfreaks.com/topic/135521-array-data-echo-into-table/#findComment-705987 Share on other sites More sharing options...
GingerRobot Posted December 4, 2008 Share Posted December 4, 2008 I'd recommend not using an array named $array though, may run into troubles.. Why's that? Since PHP uses the $ symbol for variables, there's no issue with using reserved words as variable names. Quote Link to comment https://forums.phpfreaks.com/topic/135521-array-data-echo-into-table/#findComment-705991 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.