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

Switch detects zeros as ones! don't know why!

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Switch detects zeros as ones! don't know why!

Postby sametch » Fri Feb 28, 2003 9:13 am

I am trying to use a switch function to display a different text message according to the numeric value of a variable. It keeps missreading zeros and treating them as ones. Is there something obvious I am missing?

here is my code

switch ($pagetype)
{
case $pagetype == 0:
echo "Standard";
break;
case $pagetype == 1:
echo "Custom (using include)";
break;
case $pagetype == 2:
echo "External Link (same window)";
break;
case $pagetype == 3:
echo "External Link (new window)";
break;
default:
echo "Standard";
}

if I pass it the variable $pagetype when it equals 0 It responds with "custom (using include)"

sametch :?
sametch
New php-forum User
New php-forum User
 
Posts: 17
Joined: Wed Jul 03, 2002 3:10 am

Postby sametch » Fri Feb 28, 2003 10:06 am

No need to reply I have the answer it should read "case 0:" not "case $pagetype == 0: "

:)
sametch
New php-forum User
New php-forum User
 
Posts: 17
Joined: Wed Jul 03, 2002 3:10 am

Postby Romantik » Sat Mar 01, 2003 3:35 am

switch ($pagetype)
{
case $pagetype = 0: echo "Standard"; break;
case $pagetype = 1: echo "Custom (using include)"; break;
case $pagetype = 2: echo "External Link (same window)"; break;
case $pagetype = 3: echo "External Link (new window)"; break;
default: echo "Standard";
}
Romantik
New php-forum User
New php-forum User
 
Posts: 67
Joined: Mon Feb 24, 2003 2:55 am
Location: ../Ukraine/Kherson


Return to PHP coding => General

Who is online

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

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