Skip to main content

🛍️ BLACK FRIDAY get-one-give-one sale is underway. Don't miss $50 off PLUS a free subscription to gift a friend. 🤩

🚀 In our NEW AI Bootcamp you'll build a working app in 28 days, no experience required. Free to all subscription levels.

Join the Treehouse affiliate program and earn 25% recurring commission! 🤑

  • Treehouse Logo
    • For Individuals
    • For Businesses
    • For Schools
    • For Libraries
    • For Military
    • All Courses
    • Tracks
    • AI Bootcamp
    • College Credit
    • Techdegree Bootcamps
    • Front End Development
    • Full Stack JavaScript
    • Code Adventures
    • Discord
    • Forum
    • Success Stories
    • Treehouse Links
    • 100 Days of Code
    • Explore
    • Career Toolbox
    • Free Treehouse Near Me
    • Affiliates
    • Blog
    • Support
    • About
    • Learn
    • Beginner's Guide to Coding
    • Data Analysis with SQL & Python
    • Front-End Web Development
    • Python Programming Basics
    • Techdegree Bootcamp Overview
    • UX Design Fundamentals
    • AI Tools for Beginners
  • For Individuals For Businesses For Schools For Libraries For Military
  • All Courses Tracks AI Bootcamp College Credit
  • Techdegree Bootcamps Front End Web Development Full Stack JavaScript
  • Code Adventures Discord Forum Success Stories Treehouse Links 100 Days of Code
  • Explore Career Toolbox Free Treehouse Near Me Affiliates Blog Support About
    Learn Beginner's Guide to Coding Data Analysis with SQL & Python Front-End Web Development Python Programming Basics Techdegree Bootcamp Overview UX Design Fundamentals AI Tools for Beginners
  • Sign In
  • Free Trial
Instagram Twitter Facebook YouTube LinkedIn
Loading banner... Start your free trial at Treehouse
    • Newest
      • Newest
      • Active
      • Unanswered
      • Featured
    • All Topics
      • All Topics
      • • General Discussion
      • • AI
      • • APIs
      • • Coding for Kids
      • • College Credit
      • • Computer Science
      • • CSS
      • • Data Analysis
      • • Databases
      • • Design
      • • Development Tools
      • • Digital Literacy
      • • Game Development
      • • Go Language
      • • HTML
      • • Java
      • • JavaScript
      • • Learning Resources
      • • Machine Learning
      • • No-Code
      • • PHP
      • • Professional Growth
      • • Python
      • • Quality Assurance
      • • React
      • • Ruby
      • • Security
      • • Swift
      • • Vibe Coding
  • ei2
    ei2
    2,618 Points

    Help with "foreach" loops

    Posted May 9, 2019 4:44pm by ei2
    ei2
    2,618 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    2 Answers

  • Amy Hsieh
    Amy Hsieh
    6,023 Points

    Why do we need to create a new variable $ID and assign the information of $item in it?

    Posted December 6, 2018 8:22am by Amy Hsieh
    Amy Hsieh
    6,023 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    1 Answer

  • Sean Flanagan
    Sean Flanagan
    33,237 Points

    Code appears in preview

    Posted September 27, 2018 12:13am by Sean Flanagan
    Sean Flanagan
    33,237 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    1 Answer

  • Cliff Jackson
    Cliff Jackson
    2,887 Points

    No images displaying on page?

    Posted August 4, 2018 12:22pm by Cliff Jackson
    Cliff Jackson
    2,887 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    1 Answer

  • jlampstack
    jlampstack
    23,932 Points

    Variables used in foreach loop are confusing

    Posted May 9, 2018 4:14pm by jlampstack
    jlampstack
    23,932 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    1 Answer

  • john paul
    john paul
    3,191 Points

    My browser is generating many warnings

    Posted April 2, 2018 5:18pm by john paul
    john paul
    3,191 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    3 Answers

  • Alex Forseth
    Alex Forseth
    8,017 Points

    get_item_html function structure. How does it work?

    Posted February 3, 2018 9:30am by Alex Forseth
    Alex Forseth
    8,017 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    3 Answers

  • yalın küçük
    yalın küçük
    4,810 Points

    Do we have to put a variable ( argument) in function we do not need or use within? I do not understand.

    Posted October 29, 2017 6:52am by yalın küçük
    yalın küçük
    4,810 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    0 Answers

  • Gremyko Coleman
    Gremyko Coleman
    9,756 Points

    Was the function for this video needed?

    Posted August 10, 2017 5:24am by Gremyko Coleman
    Gremyko Coleman
    9,756 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    0 Answers

  • Logan Fox
    PLUS
    Logan Fox
    Courses Plus Student 3,379 Points

    Fatal error: Uncaught Error: Call to undefined function get_item_html() in /home/treehouse/workspace/index.php:21 Stack

    Posted July 8, 2017 2:01pm by Logan Fox
    Logan Fox
    Courses Plus Student 3,379 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    2 Answers

  • Trevor Jones
    Trevor Jones
    1,962 Points

    Please help me understand the logic of "as $id => $item" when declaring our function in foreach loop.

    Posted April 30, 2017 1:49am by Trevor Jones
    Trevor Jones
    1,962 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    4 Answers

  • jlampstack
    jlampstack
    23,932 Points

    What does $id and $item point to?

    Posted April 17, 2017 4:11pm by jlampstack
    jlampstack
    23,932 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    1 Answer

  • jlampstack
    jlampstack
    23,932 Points

    foreach($random as $id)

    Posted March 8, 2017 9:52pm by jlampstack
    jlampstack
    23,932 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    0 Answers

  • jlampstack
    jlampstack
    23,932 Points

    Why is it better to return the HTML function to the code as text assigned to a variable instead of using echo?

    Posted March 8, 2017 9:05am by jlampstack
    jlampstack
    23,932 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    3 Answers

  • Josh Newman
    Josh Newman
    4,421 Points

    Problem with understanding

    Posted January 8, 2017 6:30pm by Josh Newman
    Josh Newman
    4,421 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    4 Answers

  • John Vicencio
    John Vicencio
    6,413 Points

    Nothing is displaying for full catalog?

    Posted September 2, 2016 5:01pm by John Vicencio
    John Vicencio
    6,413 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    2 Answers

  • Andrew Phythian
    Andrew Phythian
    19,747 Points

    "This works, but it's better with functions like this to return the HTML to the main code as a piece of text instead"

    Posted July 15, 2016 9:34pm by Andrew Phythian
    Andrew Phythian
    19,747 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    2 Answers

  • Alexander Bogdanov
    Alexander Bogdanov
    2,587 Points

    Why do we need the $id variable??????

    Posted June 26, 2016 11:37am by Alexander Bogdanov
    Alexander Bogdanov
    2,587 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    3 Answers

  • john larson
    john larson
    16,594 Points

    Can someone explain why this code outputs 321

    Posted June 6, 2016 12:46am by john larson
    john larson
    16,594 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    5 Answers

  • Trần Phúc
    Trần Phúc
    2,264 Points

    issue Using varies in funciton.php

    Posted May 20, 2016 12:41am by Trần Phúc
    Trần Phúc
    2,264 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    1 Answer

  • Javid Abbasov
    Javid Abbasov
    9,243 Points

    Dots between code

    Posted March 2, 2016 6:47pm by Javid Abbasov
    Javid Abbasov
    9,243 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    2 Answers

  • ammarkhan
    seal-mask
    .a{fill-rule:evenodd;}techdegree
    ammarkhan
    Front End Web Development Techdegree Student 21,661 Points

    Why part of loop was made a function?

    Posted March 2, 2016 2:03am by ammarkhan
    .a{fill-rule:evenodd;}techdegree
    ammarkhan
    Front End Web Development Techdegree Student 21,661 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    1 Answer

  • Erin Barber
    Erin Barber
    1,564 Points

    Getting a "Warning: Illegal string offset 'img'..." message in place of every third catalog item

    Posted February 28, 2016 6:23pm by Erin Barber
    Erin Barber
    1,564 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    1 Answer

  • samtruss1986
    samtruss1986
    11,772 Points

    Using this custom function when webpages are in sub-folders.

    Posted January 31, 2016 7:24pm by samtruss1986
    samtruss1986
    11,772 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    1 Answer

  • Ben Os
    Ben Os
    20,008 Points

    My catalog items appear as a long list and suddenly there is no CSS in the site

    Posted January 29, 2016 3:57pm by Ben Os
    Ben Os
    20,008 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    4 Answers

  • Jagmeet Singh
    Jagmeet Singh
    2,449 Points

    foreach($catalog as $id => $item)?

    Posted January 19, 2016 6:42am by Jagmeet Singh
    Jagmeet Singh
    2,449 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    9 Answers

  • Mike Hansen
    seal-mask
    .a{fill-rule:evenodd;}techdegree
    Mike Hansen
    Python Web Development Techdegree Student 3,419 Points

    Css is weird both places now..

    Posted January 15, 2016 5:21pm by Mike Hansen
    .a{fill-rule:evenodd;}techdegree
    Mike Hansen
    Python Web Development Techdegree Student 3,419 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    2 Answers

  • Mike Hansen
    seal-mask
    .a{fill-rule:evenodd;}techdegree
    Mike Hansen
    Python Web Development Techdegree Student 3,419 Points

    Css in the catalog page is looking weird

    Posted January 15, 2016 5:01pm by Mike Hansen
    .a{fill-rule:evenodd;}techdegree
    Mike Hansen
    Python Web Development Techdegree Student 3,419 Points
    • PHP
    • Build a Basic PHP Website (2018)
    • Listing and Sorting Inventory Items
    • Creating the Display Function

    2 Answers

Posting to the forum is only allowed for members with active accounts.
Please sign in or sign up to post.

Techdegree

  • Front End Web Development
  • Full Stack JavaScript
SEE ALL

Tracks

  • Learn to Code for Beginners
  • Beginning Python
  • Beginning SQL
  • Beginning Java
SEE ALL

Courses

  • JavaScript Basics
  • Intro to HTML & CSS
  • Python Basics
  • CSS Layout
SEE ALL

About Us

  • About
  • Blog
  • Community
  • Stories
  • Contact
  • Gift Card

Explore

  • Plans
  • Affiliates
  • Perks
  • Shop
  • Free Treehouse Near Me
  • Treehouse for Libraries
  • Treehouse for Businesses

Treehouse is an online technology education platform founded in 2011. Treehouse offers more than 700 self-paced, video-based courses in web development, programming, data analysis, design, and AI, plus two project-based bootcamp programs in Front End Web Development and Full Stack JavaScript. Individual Treehouse plans start at $25 per month and include a 7-day free trial. Treehouse serves individual learners, businesses, schools, and public libraries. Cardholders at participating U.S. public libraries can use Treehouse for free. Select Treehouse courses, offered with University Pathways International, are recommended for college credit by ACE and NCCRS. Treehouse learners earn digital certificates for completed Tracks.

Terms & Conditions · Privacy · © 2026 Treehouse Island, Inc.
  • Twitter
  • YouTube
  • Facebook
  • LinkedIn
  • Instagram
  • Discord