Page 1 of 1

Loops and Variables

Posted: Fri Jun 23, 2006 9:01 pm
by Bigun
I'm trying to check the values for $songname0 through 9 and same for $songfile.

The code below is the best I could come up with. But alas, it just reads the values of $i.

Code: Select all

for($i = 0; $i < 10; $i++) {
                if ($songfile.$i != "" && $songname.$i != "") {
                        //Song Present - Run Tests
                        echo $songfile.$i."<br>";
                        echo $songname.$i."<br>";
                        echo "Slot ".$i." contains valid data<br>";
                }
        }

Posted: Fri Jun 23, 2006 9:13 pm
by Weirdan
use intermediate variable to construct the variable name you need:

Code: Select all

//.......
$currsongfile = 'songfile' . $i;
echo $$currsongfile;
//.......

Posted: Fri Jun 23, 2006 9:17 pm
by Bigun
Weirdan wrote:use intermediate variable to construct the variable name you need:

Code: Select all

//.......
$currsongfile = 'songfile' . $i;
echo $$currsongfile;
//.......
What does the extra $ do?

Posted: Fri Jun 23, 2006 9:22 pm
by Weirdan