What is the arithmetic operators in PHP?
$a + $b // sum of $a and $b
$a - $b // Difference $a and $b
$a * $b // Multiplication $a and $b
$a / $b // Division $a and $b
There is another arithmetic operator PHP, so-called integer remainder of a division.
$a % $b
If we divide 5 for example by 2, we get 2.5 and 5% 2, we get 1 (which is the residue left):
echo 5 / 2 // we get 2.5
echo 5 % 2 // we get 1
Here we come to the data types in PHP. Currently PHP supports 8 types of data types.
In this tutorial we consider only four:
PHP is a language with dynamic typing. I will explain a little – in the strongly typed language when we create a variable we immediately say what kind of data will be stored there. If we were declare that there will be a number then an attempt to put there something else will result in an error. In strongly typed languages we cannot afford to use a variable of any data type without declaring it. PHP itself is trying to determine what kind of data type is stored in variable and usually he does it correctly.
Continue reading Data Types in php – PHP Lessons
When we write code, we will get some errors. This is normal. Any programmer will get errors. PHP in this case is trying to show us where there was an error and the line of code number.
The most popular error in PHP – we do not put “;” at the end of the expression:
$user_name = "Martin";
You’ll get the following error:
Parse error: syntax error, unexpected T_ECHO, expecting ‘;’ in /htdocs/test.php on line 5.
Continue reading Errors in php – PHP Lessons
Echo command in php serves to output text. You will use the echo command more than any other. Let’s take a closer look on it!
To display the line use echo. You can use it to display the text in quotes, variables, etc. Let’s look at an example.
$myString = "Hello!";
echo "<h5>I love using PHP!</h5>";
We already did “Hello World!” output but the following command echo contains html tag. Use html tags are not prohibited as php gives us the dynamics and statics page decoration is still on ordinary html.
Continue reading Echo in php – PHP Lessons
Classic PHP programming tell us that the comments in the program should be 30% of the code. There are merely two kinds of comments: the so-called single-line and multi-line comments.
Here is the single-line comments:
# this is comment
// and this is comment also
phpinfo(); // one more comment here
Continue reading Comments in php – PHP Lessons
If you have never written a program the concept of variables may be new to you. But do not worry, it’s not so difficult!
Variable is a place to store value, such as a text string «Hello World!»(string) 4 (integer). Variable can be used anywhere in your code, instead of having to enter the actual values over and over again. In PHP you define a variable as follows:
$ variable_name = Value;
As you can see, any variable starts with a dollar sign. You need to remember that otherwise it will not work. This is a common mistake made by novice PHP programmers!
Continue reading Variables in php – PHP lessons
Before we talk about the syntax of PHP, let’s first define what is meant by the word syntax.
Syntax – the rules that must be followed to write properly structured code .
PHP syntax and semantics are similar to most other programming languages (C, Java, Perl). The only difference is that the PHP code is embedded in the html page layout . All PHP code must be contained in the following tags:
If you do not want problems , then write in standard form. This ensures that your scripts will work on servers with different settings.
Continue reading How to create php pages – PHP lessons