Re: How to do this? 6 lines of code...Parse error

From: Date: Mon, 05 Jan 2004 11:23:46 +0000
Subject: Re: How to do this? 6 lines of code...Parse error
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-173737@lists.php.net to get a copy of this message
Hi, RA> for($i=1; $i<21; $i++) RA> { if(isset($product$i)) RA> {echo "Product".$i." is set!<br>";} RA> else(!isset($product$i)) RA> {echo "Product".$i." is NOT set!<br>";}} RA> exit; ... RA> all of the above give me a parse error. Your problem is here: else(!isset($product$i)) You can't put conditions after "else": it is used as the default option if all other tests fail. You should be using "elseif" instead. Your choices are: else { echo "Product" .$i. " is NOT set!<br>"; } or elseif(!isset($product$i) { echo "Product" .$i. " is NOT set!<br>"; } In this case, as it seems to be a boolean test, the first is superior, I think. The second test adds nothing... Geoff Caplan Advantae

« previous php.general (#173737) next »