Jump to content

First number, last number... now fill in everything inbetween


ldsmike88

Recommended Posts

I'm getting this array from my database for all the items on my site. Each item or row has its own set of numbers so the first and last numbers change. I can easily get the first number because I sort the array and that would make the first variable in the array the lowest number. But how would I get the last number in the array?
Link to comment
Share on other sites

Can you please clarify? These "sets of numbers", what are they?

As for getting the last number, just use something like:
[code]$last = count($array);
$last_element = $array[$last];[/code]
This assuming your array is numeric.
Link to comment
Share on other sites

Sorry, I am making a script that will write a javascript to fill in all the required information for three select menu's. The menu's are make, model, and year. I already have this working in javascript, but it takes SOOOO long to fill in every model for each make and then every year for each model. Now I have a php script that will get the information it needs from the database and write the javascript that adds the options into the select boxes. For a working example see eGrilles.com.

Here is the final code I compiled from this topic:[code]<?
$years = '1999, 2001, 2006';
$im = explode(", ", $years);
echo min($im) . ' - ' . max($im);
echo '<br /><br />';

for ($i=min($im); $i<=max($im); $i++) {
   echo $i . '<br />';
}
?>[/code]
Link to comment
Share on other sites

ok, I updated what I am going to use. Thank you everyone for your help!

Final Code Sample:[code]<?
$array = array(2001, 1999, 2006);
$min = min($array);
$max = max($array);
$full_array = range($min, $max);
foreach($full_array as $arrayValue){
    echo $arrayValue . '<br />';
}
?>[/code]
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.