Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

What is wrong with my code?

$
0
0

This is for a class on codecademy. I'm getting a parse error for an unexpected T_variable on line 35.

 

 

 

 

 

<html>

  <head>
    <title>Iteration Nation</title>
  </head>
  <body>
    <p>
      <?php    
        $food = array('pizza', 'salad', 'burger');
        $salad = array('lettuce' => 'with',
                   'tomato' => 'without',
                   'onions' => 'with');
    
      // Looping through an array using "for".
      // First, let's get the length of the array!
      $length = count($food);
    
      // Remember, arrays in PHP are zero-based:
      for ($i = 0; $i < $length; $i++) {
        echo $food[$i] . '<br />';
      }
    
      echo '<br /><br />I want my salad:<br />';
    
      // Loop through an associative array using "foreach":
      foreach ($salad as $ingredient=>$include) {
        echo $include . ' ' . $ingredient . '<br />';
      }
    
      echo '<br /><br />';
    
      // Create your own array here and loop
      // through it using foreach!
    $candy = array('chocolate'=> 'M&Ms', 'chocolate'=>'Snickers', 'chocolate'=>'Reese\'s', 'gummy'=>'bears', 'gummy'=>'worms');
    foreach ($candy as $type => $specific);
        if $type == 'chocolate'{
            echo $specific;
        } elseif {
            echo $type . ' ' . $specific;
        } else {
            echo 'Unknown candy';
        }
      ?>
    </p>
  </body>
</html>

 

 

 

 

I'm sure it's a simple mistake. I'm new to coding.


Viewing all articles
Browse latest Browse all 13200

Trending Articles