Previous chapter: Part-1
- At the beginning of PHP coding language we have to write “ <?php ” this code to announce that we are going to prepare a php document. To end the whole PHP code we have to just write “ ?> “ this simple code.
So, the document turns to the following phase:
- To make a PHP file we must have to save the PHP code through keeping the ” .php ” extension at the end of the file name. Example: tech-info24.php .
Even if we rename a file by keeping “.php” at the last then the file will become a php file.
Showing an output
To show any output we have to use the “echo” code. It is used to show both text and the value of variables.
||The structure for showing any text is :
|This is a sample text|
|2.||The structure for showing any variables is :
If we want to show both variables and text at a time:
We have to use the dot ( . ) sign to represent both the text and the value of x.
|The value of x is 10.|
Comments on PHP are used to simplify the PHP code to the checker so that he/she can easily identify the whole code within a short time.
Two type of structures are available for that like following:
1//Comments goes here.
1/*comments goes here*/
Usage of Variables
What is variable?
Variables can be defined as the carrier of the information or storehouse of values. In different programming languages(like PHP, C programming, Java, Python, SQL, etc.) variables are used to pass values through a program.
Variables in PHP:
To input a value on the program you need to use the “ $ “ sign just before the variable name. Then we can input any value using those variables. Through those variables we can perform mathematical calculations.
In example-1, b and x are variables. The value of a and b is 10 and 20. The summation of a and b is 30. If we want to use this number for any purpose then we need to store that in a variable. So, here I have considered the “x” as the carrier of “30”. That means 30 have been stored in x. To show the value of x, I have used the “echo” to present the output.
In example-2, everything is same but there is a multiply sign(*) instead of the summation sign(+). So, the output will be different(200). So, different number will be stored on the variable “x”.
The star sign ( * ) is used as the multiply sign.