By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

switch trouble

P: n/a
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/
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

Jul 17 '05 #2

P: n/a
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

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.