PDA

View Full Version : Array Help

nickison99
06-21-2005, 04:25 PM
Hi all,
I need a little guidance about a project im working on. I pull two numbers from my database (say 3 and 7). What i need to do is find all the numbers in between 3 and 7 (inclusive) and store it in an array. Can someone help me go about doing this. THanks.
Nick

SeeIT Solutions
06-21-2005, 04:53 PM
Try this...

\$num1 = 3;
\$num2 = 7;

if (\$num1 > \$num2) {
for (\$i = \$num2;\$i <= \$num1;\$i++) {
\$numarray[] = \$i;
}
} else {
for (\$i = \$num1;\$i <= \$num2;\$i++) {
\$numarray[] = \$i;
}
}

delinear
06-21-2005, 04:54 PM
This will put all the numbers into an array inclusive of the first and second number. It also doesn't matter which number is higher, the first or second.

\$num1 = // your first db number
\$num2 = // your second db number

\$start = (\$num1 < \$num2 ? \$num1 : \$num2);
\$end = (\$num1 < \$num2 ? \$num2 : \$num1);

for(\$i = \$start; \$i <= \$end; \$i++) {
\$array[] = \$i;
}

print_r(\$array); // view the numbers in the array