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 &...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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/ |
|
|||
|
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. |
|
|||
|
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 |