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. Link to comment https://forums.phpfreaks.com/topic/280376-whats-wrong-with-my-code/ 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() Link to comment https://forums.phpfreaks.com/topic/280376-whats-wrong-with-my-code/#findComment-1441601 Share on other sites More sharing options...
DarkSuperHero Posted July 22, 2013 Share Posted July 22, 2013 <?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 ?> Link to comment https://forums.phpfreaks.com/topic/280376-whats-wrong-with-my-code/#findComment-1441623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.