Loops and Variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Loops and Variables

Post 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>";
                }
        }
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

use intermediate variable to construct the variable name you need:

Code: Select all

//.......
$currsongfile = 'songfile' . $i;
echo $$currsongfile;
//.......
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Post Reply