PHP consist of two compound types, arrays and objects.
Arrays are special types of variables that can store more than one value. Arrays are useful when you need to store related variables data under one variable name.
An array can be declare in fallowing way:
$arr-name [key]= value;
In the above statement
arr_name is the name of the array.
Key is any string or a non negative integer. if you want to modify an
array, it is best not to specify a key and to leave the square bracket
empty.
Value is the data that is held in the array.
To understand the concept arrays, consider the fallowing codes:
<?php
$arr_name[0]="My";
$arr_name[1]="name";
$arr_name[2]="is";
$arr_name[3]="Rishi";
echo "$arr_name[0] $arr_name[1] $arr_name[2] $arr_name[3] $arr_name[4]"; ?>
Objects are are the building blocks of a programming language . An object
is an entity that can hold data and specify what need to be done with
the data. Most of the internal working of an object are hidden from the
code that uses them. Objects are a bundle of variable and functions that
are derived from a class. To understand the concept of object you should
be familiar with the fallowing terminology
PHP does not require the developer to absolutely specify a data type for
a variable at the time of declaration. In PHP you need not worry about
data type mismatches in an expression. Consider the fallowing example:
<?php $myVal = 7+ "2 is my number"; echo $myVal; ?>
The output will be: 9.
In most other language ,the preceding code will not be valid. In PHP this
statement is valid, and it also generates the expected output. This is
because in PHP a variable doesn't have fixed data type assign to it and
can store any data type. The result of an expression is calculated on the
basic of the operator and not on the basic of the operands. Examine the
fallowing code for a better understanding of juggling data type:
<?php
$a = "Rishi";
$a +=2; // The += operator is use to add the initial value assigned to // the variable to the number specified.r> echo?>
The output will be : 2
In the above example ,$a contains a value that is of the string data type. In
the next line, the += operator changes the initial variable assigned to
$a to 2.
Consider another example where the .= operator is used to concatenate
string:
<?php
$a = "Rishi";r> $a .=2; //The .= operator is use to concatenate two string .
echo $a; //The value of $a is now Rishi2
?>
The output will be: Rishi2
The . = operator tells the PHP that the number 2 is a string even though
it is not specified in single quotes or double quotes. As a result it
concatenates the initial value with the new value of $a, and the output
is Rishi2.
A constant is a name that identifies a simple value. By nature, a
constant is the opposite of a variable because the value of a constant
remains fixed and doesn't change when the script is executed. Constant
have the fallowing characteristics:
-
A constant is case sensitive by default.
-
By convention, constant are expressed in uppercase letters.
-
A consent can begin with either an underscore or with a letter, fallowed
by any number of underscore, letters or numbers.
A constant name never begins with a dollar sign .
-
After a constant is set, it is not possible to to redefine or undefined
it.
-
A constant can contain only scalar data type like : Boolean, integer, float and
string.
-
A constant can be accessed and use anywhere in a script regardless of
variable scoping rules.
<?php
define ("ADMIN_MAIL" ,"contatc@a2zwebhelp.com");
echo MIN_MAIL; ?>