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 PHP Basics (Retired) PHP Conditionals & Loops Foreach Loops

alexvalladares
alexvalladares
21,478 Points

This can be made also via jQuery or JavaScript

The question is: when do we use php, javascript or jquery for these kind of (simple) operations?

2 Answers

PHP is server side, so it will return the same thing at the same speed regardless of what computer you're on. The user can't see the code typically, so it's better for manipulating sensitive data. You would use PHP for things that happen on page load, since it can't really do much once it's served you the html.

Javascript runs on the users computer, making it reliant on their hardware and installed version. Anybody can see what you've written in Javascript with little effort. But, it is necessary for things you want to happen after the page is already loaded, such as AJAX requests to the server and animations.

For simple operations, use javascript to minimize operations on your server or php for reliability. Or just use whatever you happen to be writing in when the operation comes up.

alexvalladares
alexvalladares
21,478 Points

Great answer, John. Really appreciate it!

No problem :)