Jump to content

What's wrong with my code?


Loose_Goose

Recommended Posts

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


<?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
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.