Skip to main content

PHP variable and constant

What is variable? 
A variable is a representation of a value. Let's take for instance, A=40; the representation of 40 is A, so A is called the variable. For storing information,  a variable can be called "containers".

Rules for variable 
1. Add a $ (dollar sign) in front or before the variable name.
For example: $No_of_oranges
2. The PHP cannot begin with numerals; despite the fact of adding the dollar sign ($) in front of the variable name. The variable name must begin with alphabets or underscore sign(_).
3. The PHP variable may contain the following characters:

  • Numerals: (0-9)
  • Alphabets: (A-Z) or (a-z) 
  • Underscore: (_)
4. PHP variables are case sensitive. ie. $No_of_oranges and $NO_OF_ORANGES are different variable
5. Variable name can be any length long.

Variable Types:
1. Scalar types:

  • Boolean
  • Integer
  • Float
  • String
2. Compound types:

  • Object
  • Array
3. Special types:

  • Resource 
  • Null
Let's take an example:
<?php
$string_value="hello simply lecture! ";
$integer=126;
$float=3.658;
$boolean=true;
$array=array(1,2,3);
$object=new subject_name();
$null_variable=NULL;
?>

Constants 
PHP constants are similar to variable but they cannot be changed when the script is executed.
The basic features of a constant that distinguish them from a variable are:

  • Constants don't require the $ (dollar sign) before their names 
  • Constants are usually uppercase that distinguish them from normal variable
  • define() is used to define a constant, it requires the name and the value of the name.
Example:
 define("subject name","simply lecture");

  • You can check if a given constant name exist or not.
 Example:
if (defined("subject_name"))
echo "constant subject_name exist";

Pre-defined variables
Pre-defined variables are already installed or defined variables, and PHP provides a large number of pre-defined variables to its users. This pre-defined variables are called "super globals".
The pre-defined variables are given below:

  • $GLOBALS - All variables available in global scope.
  • $_SERVER - Server and execution environment information.
  • $_GET - HTTP GET variable.
  • $_POST - HTTP POST variable.
  • $_FILES - HTTP File upload variable. 
  • $_SESSION - Session variable.
  • $_REQUEST - HTTP Request Variable.
  • $_ENV - Environment variable.
  • $_HTTP COOKIES - HTTP cookies.




Comments

Popular posts from this blog

Schrodinger equation as a law in physics

The unified theory of wave-particle duality has been used to derive the Schrödinger equations. The Schrodinger equations are generally accepted, by postulate rather than derivation, to be laws of physics. The Schrodinger equations provide a basis for analyzing many kinds of systems (molecular, atomic, and nuclear) in a particular inertial reference frame. The success of the Schrödinger equations constitutes a basis for accepting them, their derivations, and the unified theory of wave-particle duality which makes such derivations possible. This acceptance is completely justified in the favored inertial reference frame. In accord with the principle of relativity, all physical laws must be the same in all inertial reference frames, i.e., all physical laws must be Lorentz invariant. Recall, the relationship: $$\nabla^{2} \psi = \frac{\partial^{2} \psi}{\partial t^{2}}$$ ...........(1) Equ (1) is Lorentz invariant and reduces, by means of the procedure presented in the previou

Maxwell first equation

The Maxwell first equation in electrostatics is called the Gauss law in electrostatics. Statement:  It states that the total electric flux \(\psi_E\) passing through a closed hypothetical surface is equal to \(\frac{1}{\epsilon_0}\) enclosed by the surface. Integral Form: $$\phi_E = \int E.ds = \frac{q}{\epsilon_0}$$ $$\int D.ds = q$$ where, $$D = \epsilon_0 E = displacement-vector$$ Let the change be distributed over a volume v and \(\rho\) be the volume charge density. Hence, $$q = \int \rho dv$$ Therefore; $$\int D.ds = \int_{v} \rho dv$$ .........(1) Equ(1) is the integral form of Maxwell first law Differential form: Apply Gauss divergence theorem to the L.H.S of equ(1) from surface integral to volume integral. $$\int D.ds = \int (\nabla.D)dv$$ Substituting this equation to equ(1) $$\int(\nabla.D)dv = \int_{v} \rho dv$$ As two volume integrals are equal only if their integrands are equal. Thus; $$\nabla.D = \rho v$$ ............(2) Equ(2) is the differe

Auxiliary time dependent Schrodinger equation

Recall the relationship: $$\phi(t) = C_+ exp[-i(\frac{E}{\hbar})t] + C_- exp[i(\frac{E}{\hbar})t]$$ .............(1) Recall, from the present special case: $$C_+ = 0$$ ........(2) Substitute equ (2) into equ (1), we have that: $$\phi(t) = C_- exp[i(\frac{E}{\hbar})t]$$ .......(3) Also,  recall the relationship: $$\Psi(r,t) = \psi(r) \phi(t)$$ ..........(4) Substitute equ (3) into equ (4): $$\Psi(r,t) = C_- exp \psi (r)  [i(\frac{E}{\hbar})t]$$ ..............(5) Equ (5) can be differentiated with respect to t, and by rearranging we have: $$\Psi(r,t) = -i(\frac{\hbar}{E}) \frac{d \Psi (r, t)}{dt}$$ ..............(6) Recall the relationship: $$-\frac{\hbar^{2}}{2m} \nabla^{2} \Psi(r,t) + V(r) \Psi(r,t) = E \Psi(r,t)$$ ...........(7) Substituting equ (6) into the right hand side of equ (7) we have: $$-\frac{\hbar^{2}}{2m} \nabla^{2} \Psi(r,t) + V(r) \Psi(r,t) = i\hbar \frac{d \Psi(r,t)}{dt}$$ .........(8) Equ (8) is the auxiliary time dependent Schrodinger equation