switch trouble

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I've got the switch structure right:

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

     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 /

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


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.

Re: switch trouble

Dinguss wrote:
Quoted text here. Click to load it

Indeed, it is correct syntax.

Quoted text here. Click to load it

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


Site Timeline