Jump to content

Search the Community

Showing results for tags 'array foreach if codecademy'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Check out my third array. It's only printing out "Reese's" and "gummy worms." I want it to display "M&M's," "Snickers," "Reese's," "gummy bears," and "gummy worms." I'm doing this for my codecademy course. The important part starts on line 33. I'm new to coding. <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."<br></br>"; } else { echo $type . ' ' . $specific; } continue; endforeach; ?> </p> </body> </html>
×
×
  • 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.