switch trouble

This is a discussion on switch trouble within the PHP Language forums, part of the PHP Programming Forums category; I've got the switch structure right: switch ($i) { case 1: print "i equals 1"; break; default: print &...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-17-2005
Dinguss
 
Posts: n/a
Default switch trouble

I've got the switch structure right:

switch ($i) {
case 1:
print "i equals 1";
break;

default:
print "i doesn't equal 1";
}

But no matter what I do it always executes the default code block. How
do I pass a value for $i to the program?

--
Dinguss (Michael Bradley-Robbins)

http://www.douglasguitars.com/
Reply With Quote
  #2 (permalink)  
Old 05-17-2005
ZeldorBlat
 
Posts: n/a
Default Re: switch trouble

Are you setting a value for $i?

At the top of the code put:
$i = 1;
and then see what happens.

If you're talking about running the script from the command line and
want to pass a value for $i, check out

http://us3.php.net/reserved.variables

and read about argv. If you're running it as a webpage, it'll need to
come from somewhere...probably (but not necessarily) an HTML form.

Reply With Quote
  #3 (permalink)  
Old 05-17-2005
Oli Filth
 
Posts: n/a
Default Re: switch trouble

Dinguss wrote:
> I've got the switch structure right:


Indeed, it is correct syntax.

> switch ($i) {
> case 1:
> print "i equals 1";
> break;
>
> default:
> print "i doesn't equal 1";
> }
>
> But no matter what I do it always executes the default code block.


Where is the value for $i coming from, i.e. where is $i set?

--
Oli

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:33 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0