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?
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]
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.