Hello, and welcome to my first PHP tutorial.
We'll start by the basics and over time add new content.
If you have any questions about this tutorial, reach out at any time, we're here to help you develop your skills within the world of programming languages. Good luck!
WHAT IS PHP?
- PHP stands for Hypertext Preprocessor;
- PHP was created in 1994 by Rasmus Lerdorf;
- PHP is a server-side scripting language;
- PHP is free and widely used for web applications;
- PHP is compiled on the fly;
WHAT CAN YOU DO WITH PHP?
- PHP can generate dynamic content for your web pages;
- PHP can write, read, update and delete files on your web server;
- PHP can collect data from web forms;
- PHP can write, read, update and delete data from your database;
- PHP can be used to control user accesses to web pages;
- PHP can process, modify and encrypt data; and more.
SYNTAX & $Variables
- PHP Scripts start with
<?php
and end with ?>
;
- PHP keywords (
echo
, if
, else
, foreach
, while
, true
, …) are not CASE SensITive;
- Yet, the standard is to use lowercase when applying such keywords;
- PHP variables are, in another hand, case sensitive;
- You can adopt notes/comments on your code using:
//
or #
for one-line comments; OR
/* ….. */
for a multi-line comment;
- PHP variables start with the dollar sign (
$
) and are followed by a letter, for example: $my1stNameIs
or $HelloWorld
;
- Functions, ifs, whiles and other statements are delimited by brackets (
{ … }
);
- Variables allow you to store information, for example:
$myName = “Joao Morais”;
$myAge = 63;
$myDogsName = ‘Rebecca’;
- You can display the contents of your variables using echo, print or var_dump:
echo $myName; // outputs: Joao Morais
var_dump($myAge); // outputs: int(28)
- Variables can be of different types, such as:
- String (
“hello world”
; “Joao”
; “Another random string”
);
- Integer (
1
; 26
; 9934
);
- Double (
10.50
; 66.2345
);
- Boolean (
True
; False
);
- Array (
[“item 0”, “item 1”, 2, false]
);
- Object (
\stdClass
);
- NULL; (
null
);
OPERANDS ? :
- There are different types of operands:
Arithmetic:
Assignment:
Comparison:
Incremental:
Logical:
- String:
- Array; and
- Conditional Assignment: