PHP Variable- variables are termed as containers and we can place data into these containers and then, we can use these containers data by simply naming the container.
PHP Variable Naming Rules/Conventions- When we name a variable, we need to keep following things in mind- A variable starts with the $ sign, followed by the name of the variable
- A variable name must start with a letter or the underscore character
- A variable name cannot start with a number
- A variable name can only contain alpha-numeric characters and underscore (A-z, 0-9, and _ )
- Variable names are case-sensitive ($age and $AGE are two different variables)
E.g.
<?php
$msg='Hello PHP';
echo $msg;
?>
Output: Hello PHP
Constant is an identifier for a fixed value. A constant value cannot change during the execution of the script and useful for storing data that does not change while the script is run.
We can define the constant using define() function which accepts two arguments the name of the constant and its value.
E.g.
<?php
define("pi","3.14159");
$r=10;
$area=pi*$r*$r;
echo $area;
?>
PHP Function
Function is a group of reusable codes which can be called from anywhere in the program. This eliminates the need of writing the same code again and gain.
In PHP we can use inbuilt functions and also we can create our won PHP functions by using Function keyword followed by unique function name, can specify a list of parameters/values and a statement block surrounded by curly brackets {}
PHP function syntax-
Function function_name(Parameter/value list)
{
Statement(s);
}
E.g.
Function mymsg()
{
echo "Hello PHP";
}
mymsg();
Elementary Server Side Scripting through PHP
- PHP Introduction
- How to save PHP page
- PHP variables and their naming conventions
- PHP program to find maximum of 5 numbers
- PHP program to find minimum of 5 numbers
- PHP program to find sum of 2 numbers
- PHP program to find subtraction of 2 numbers