Jump to content

array data echo into table


hsub

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.