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

New No-Code Track! 🚀start learning today!

🌟 Dreaming of a bright future? 🎓 Ask about the Treehouse Scholarship program! 🚀

✨ Earn college credits in Cybersecurity, JS, HTML, CSS and Python

  • Treehouse Logo
  • Plans
    Chevron
    • For Individuals
    • For Businesses
    • For Schools
    • For Libraries
    • For Military
  • Library
    Chevron
    • All Courses
    • Tracks
    • College Credit
  • Techdegree
    Chevron
    • Overview
    • Front End Development
    • Full Stack JavaScript
    • Data Analysis
    • UX Design
    • Python
  • Community
    Chevron
    • Code Adventures
    • Discord
    • Forum
    • Success Stories
    • Treehouse Links
    • 100 Days of Code
  • Resources
    Chevron
    • Career Toolbox
    • CodeForward
    • Free Treehouse Near Me
    • Jobs
    • Blog
    • Support
    • About
  • For Individuals For Businesses For Schools For Libraries For Military
  • All Courses Tracks College Credit
  • Overview Front End Web Development Full Stack JavaScript Python Development Data Analysis UX Design
  • Code Adventures Discord Forum Success Stories Treehouse Links 100 Days of Code
  • Career Toolbox CodeForward Free Treehouse Near Me Jobs Blog Support About
  • Sign In
  • Free Trial
Instagram Twitter Facebook YouTube LinkedIn
    • Newest
      • Newest
      • Active
      • Unanswered
      • Featured
    • All Topics
      • All Topics
      • • General Discussion
      • • AI
      • • Android
      • • 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
  • 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,236 Points

    Code appears in preview

    Posted September 27, 2018 12:13am by Sean Flanagan
    Sean Flanagan
    33,236 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.

    Treehouse

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

See Full Catalogue

Techdegree

  • Front End Web Development
  • Full Stack JavaScript
  • Python Development
  • Data Analysis
  • UX Design

Tracks

  • Learn to Code for Beginners
  • Beginning Python
  • Beginning SQL
  • Beginning Java
  • ...see more

Courses

  • JavaScript Basics
  • Intro to HTML & CSS
  • Python Basics
  • CSS Layout
  • ...see more

Explore

  • Plans
  • Affiliates
  • Perks
  • Free Treehouse Near Me
  • Treehouse for Libraries
  • Treehouse for Businesses
  • Twitter
  • YouTube
  • Facebook
  • LinkedIn
  • Instagram
Terms & Conditions | Privacy

© 2025 Treehouse Island, Inc.