Loose_Goose Posted July 21, 2013 Share Posted July 21, 2013 I'm a beginning coder, and I put this together. Here it is; <?php $pizzaS['slice1']='meat'; $pizzaS["slice2"]='meat'; $pizzaS['slice3']='meat'; $pizzaS['slice4']='veg'; $pizzaS['slice5']='veg'; $pizzaS['slice6']='veg'; $pizzaS['slice7']='veg'; $pizzaS['slice8']='meat'; foreach($pizzaS as $key=>$value){ if($value==meat){ echo "I'll take that slice<br/>";} else{ echo "You can have that one<br/>";} ?> I'm getting the output I want but every other line says something about an 'assumed variable.' I can't figure out what I'm doing wrong here. I'd appreciate some help. Quote Link to comment Share on other sites More sharing options...
fastsol Posted July 21, 2013 Share Posted July 21, 2013 You need quotes around 'meat' in the if() Quote Link to comment Share on other sites More sharing options...
DarkSuperHero Posted July 22, 2013 Share Posted July 22, 2013 (edited) <?php $pizzaS['slice1']='meat'; $pizzaS['slice2']='meat'; $pizzaS['slice3']='meat'; $pizzaS['slice4']='veg'; $pizzaS['slice5']='veg'; $pizzaS['slice6']='veg'; $pizzaS['slice7']='veg'; $pizzaS['slice8']='meat'; foreach($pizzaS as $key=>$value){ if($value== "meat"){ // This line needed to have `meat` in quotes echo "I'll take that slice<br/>"; } else { echo "You can have that one<br/>"; } } //original snippet missing closing brace ?> Edited July 22, 2013 by DarkSuperHero Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.