Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Basic PHP Website Listing and Sorting Inventory Items Sorting Array Items

Josh Coast
Josh Coast
5,111 Points

If I add a movie called "Apple" to the data.php it ends up at the bottom of the list instead of the front? Why?

When I add a movie to data.php with the title "Apple" and a key of 204, it ends up at the bottom of the list instead of first? When I comment out the $sort = ltrim($sort, "A "); and $sort = ltrim($sort, "An "); lines, Apple ends up at the front again. I didn't forget the space after the A string. I'm not sure what's going on here. Any ideas?

Just remember that The ltrim() function removes whitespace or other predefined characters from the left side of a string. So it removes the A in both cases

2 Answers

Josh Coast
Josh Coast
5,111 Points

Ah, thanks Jacques Olivier, I thought that it had to match the full string, including the space, to be removed.

You are welcome. Check out the PHP docs, they can be difficult to read at times but once you get use to it, it becomes much easier to find a reference there.