Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Basic Question

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Basic Question

Postby chson » Thu Nov 14, 2002 5:06 pm

Does anybody know how I'd make the:

$test.$i

loop so it's read by the program as $test1 and then $test2?

The result of the program should be:

FAIL

PASS

Code: Select all
<?

$test1 = 1;
$test2 = 2;

for ($i=1; $i<3; $i++) {
     if ($test.$i == $test2)
                echo "PASS<p>";
        else
                echo "FAIL<P>";
}

?>
chson
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Oct 14, 2002 5:57 pm

Postby Dmitrit Plakhotnik » Fri Nov 15, 2002 1:25 am

Very simple:
Code: Select all
<?

$test1 = 1;
$test2 = 2;

for ($i=1; $i<3; $i++) {
     if (($test.$i) == $test2)
                echo "PASS<p>";
        else
                echo "FAIL<P>";
}

?>
Dmitrit Plakhotnik
New php-forum User
New php-forum User
 
Posts: 13
Joined: Fri Nov 01, 2002 6:56 am

Postby chson » Fri Nov 15, 2002 9:13 pm

Thanks Dmitrit. I will give it a shot tommorrow.
chson
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Oct 14, 2002 5:57 pm

Postby chson » Sat Nov 16, 2002 9:05 pm

What if there's also an array involved in the variable? This currently doesn't work:

if (($test.$i.[$i]) == $test2)

Neither does this:

if (($test.$i[$i]) == $test2)
chson
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Oct 14, 2002 5:57 pm

Postby chson » Mon Nov 18, 2002 9:53 am

BUMP
chson
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Oct 14, 2002 5:57 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron