You’ve decided to immerse in the world of web developing and PHP is the tool that caught your eye as is one of the most useful ones out there. Learning how to use it is like learning any other spoken language so it might be overwhelming or frustrating sometimes, but don’t give up, be aware that all PHP experts started from scratch and with the help of an incredible amount of tips and practice they came to be what they are now.
Also, don’t desperate. In order to run, you’ve got to learn how to walk first, so follow this quick guide to ease your path and take your first steps in PHP.
PHP allows your script to do calculations, read and write documents or any other kind of file, interact with databases or process information provided by the user. It’s often used with the Apache Web servers which receive the requests and later send them to the PHP interpreter, then returned to the server and last, sent to the user browser.
PHP is not like CGI scripts because it allows you to embed its code into regular HTML pages and execute the PHP code when requested instead of writing additional code to output HTML.
One of the things you have to know is that every PHP statement is needed to end in a semicolon. Even when omitting the semi colon of the last line of the code won’t cause any harm, it is a common rookie mistake not to include them in the other statements. PHP allows you to comment the code (which is very important when working on long projects to help you remember the function of a variable or some tags).
Just like in any other language, the work with variable is fundamental. PHP allows you to create a great amount of kinds of variables where you can find floating point numbers, strings, arrays and integers. A great advantage is that PHP is able to detect the kind of variable is defined while other languages require you to define the kind of variable. To define a new one you just have to put a dollar sign before a letter. PHP is case sensitive so $t and $T are two different variables. Another good thing to keep in mind is that variables defined with a name that starts with a number or any other kind of non-alphabetical character won’t be valid.
To define a variable all you have to do is write the name and put an equal sign right after it and then assign the desired value. You can do various assignments as well. Depending on the assignment you will create a kind of variable. A value like “true” or “false” will create a Boolean; a number will create an integer, a decimal number will make it a floating point and anything between apostrophes will make a string.
These are the baby steps in the PHP world. Keep researching and practicing the basics in order to improve!