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 trial

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 :)