Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPiccia Neri
8,937 PointsDifficult to understand the application of php
Hi there, I understand the explanations but the course doesn't really make me understand what all of this serves for in the real world. It would be much more useful to see real examples in an existing website. Like this, it is all abstract and I don't really see the point of it. For instance do I use an array for? what's a practical application of it? no idea. Can we see applied examples?
Sherrie Gossett
14,924 PointsIn the first 30 seconds of the first video Hampton mentions that the original idea behind PHP was to make repetitive web tasks, with HTML, easier to do. So that's one practical application. Examples: instead of repeating header and footer HTML code (or other shared content) that is supposed to appear on every page of a site, you can create a PHP file storing that information in one place: and simply "trigger it" with a very short string of PHP on each page. (This also makes those shared elements easier to alter, in the same way that having CSS in an external file makes it easier to create style updates across a site: you don't have to alter every single HTML page.)
So let's imagine you've moved your header code to a file called header.php (and this file is in a folder called "inc" - for "include.") Now, how do you include it on every web page of your site? With the PHP "include" command. You can just paste a statement at the top of your HTML page like this:
<?php include("inc/header.php"); ?>
And that will plug in your HTML header code block.
If you did the same for your footer HTML code, you could place this "include" command at the bottom of your HTML page:
<?php include('inc/footer.php') ?>
And that would plug in your HTML footer code block.
As Jo mentioned, you'll be doing this very thing shortly, when you get to the first PHP project. A little patience will pay off. You just have 2 very short stages: PHP Basics and PHP Functions to get through, since you need to have a few basic tools before you start using them.
There are tons of things you can use PHP for - serving up the number of subscribers to an email list so that it displays on a call-to-action enticing more people to sign up, serving up products on different pages of an ecommerce site, 'personalized' user interactions with a website...
5 Answers
Andrew Shook
31,709 PointsA real world application for PHP would be Facebook, which is written in PHP and Hack ( a custom PHP like language developed by Facebook). Like Logan mentioned, PHP is used, along with MySQL, to generate web page content on the fly. For example, Facebook doesn't have a static html page for every one of it's user's news feed. Instead, it most likely ( I don't work for Facebook so I'm not 100% sure) using a single html template with PHP to display all news feed for every user. In essence what happens when you go to your news feed is that FB takes you user name and look's you up in their database ( PHP is used to make the DB request and to determine which user you are). Once it retrieves your info from the DB, FB using some logic and your user settings to determine who's post and their order for your news feed. Then It makes another DB call to get the posts for your news feed. The post are likely retrieved from the DB in an array, and then that array is looped through to display the posts to your news feed.
I this give you an idea of what PHP is used for. I know my example is a little vague. Unfortunately, treehouse's php course is a little lacking. You can find courses on basic PHP, and the WordPress and Laravel ( both of which are written in PHP), but not any courses that going into detail about how to implement PHP. I wish treehouse would do a Treebook series like they did with php. I think that would help people get a better feel for PHP.
Piccia Neri
8,937 PointsThanks everyone – thanks Jo, I did think about the Build a Simple PHP application course and I will probably do it now. That's why the other Treehouse courses work so well, because you learn by making.
I do know what PHP is for, but the way the course is conceived does nothing to explain why it is useful, and when, and how I could use it. It's good to know that an array stores information, but what do I do with it? if you see what I mean. The course just doesn't show it and I ma getting bored.
The only reason why I want to understand PHP is because I want to understand Wordpress inside out. Treehouse have just changed the Wordpress track (which before had the Build a PHP application course inside it): now they say that to do the Wordpress course, they assume you already know PHP. Well, in my opinion this change is not an improvement at all. If anything, they should have done the opposite: a PHP course for Wordpress users. No such course exists, alas. There is literally NO course out there that explains just HOW Wordpress uses and needs PHP. They all 'assume' you know PHP.
But the only reason why I need PHP is because of Wordpress, so a Wordpress course should really contain a unit called 'PHP for Wordpress'. It would be so beautiful, so helpful, so simple. I have access to many PHP and Wordpress courses and not one does this simple thing. Wordpress courses assume PHP knowledge, while PHP courses all start from something completely abstract and talk about eyes colours etc and they completely lose me, I totally lose interest because what they are showing me has no obvious use to me without an example of a practical application.
The main selling point of the Wordpress track on Treehouse for me was precisely the fact that it contained a PHP course, so I thought that perhaps FINALLY someone would have thought to explain how the two work together – but no such luck. I absolutely love the Treehouse courses otherwise, so please can someone take heed? can we have a PHP course that deals specifically with Wordpress? I am never going to be a PHP developer but I do need to understand it because of Wordpress.
Thank you all!
Piccia
Ricardo Vargas
3,583 PointsWell, you said it, with PHP you can make things like WordPress...
Logan R
22,989 PointsI actually kinda thought like you did when I first used PHP too. I didn't see a lot of point to learning it. The thing that really changed my opinion was when I started working with databases. I could take user information, like usernames, how much money a user has, etc, and DO things with it. I could create cool applications that people could interact with. I don't know if that makes much sense or not.
As for arrays, they are just simply a list of items. It's an easy way to store the list and the information inside of them and you can also manipulate the lists very easily. If you want to store a shopping list, you would create an array called "Shopping List" and list your items, such as "Apples, Milk, etc".
Larry Kenebrew Jr
5,378 PointsThe OP's point is valid and this is the reason why I've had so much trouble learning php. Very few programmers are good teachers. We really need real world tutorials. Teach us php for making apps that people use in the real world like tinder, pof, or facebook.
There's no point in learning a bunch of php functions if you will not be taught how to apply them to make useful apps.
wouterb
1,307 PointsComing from the Javascript basic course I have to say this course is very disappointing quality wise. I think Teamtreehouse should completely rethink this php course.
Jo Rigg
5,294 PointsJo Rigg
5,294 PointsI did the PHP Basics course and now I've just started the Build a Simple PHP Application course and that takes you through using PHP on an example website so you start to see how it fits in 'in the real world'.