Datatype refers to kind of data a variable can store .
PHP has the following datatypes :-
Booleans : is_bool() -- Finds out whether a variable is a boolean
It retuns true if the variable is booleans.
Integer : is_int() -- Find whether a variable is an integer
It return true if the variable is integer.
Float : is_float() -- Finds whether a variable is a float
It return true if the variable is float.
String : is_string() -- Finds whether a variable is a string
It return true if the variable is string.
Array : is_array() -- Finds whether a variable is an array
It returns true if the variable is array.
array()
is a language construct used to represent arrays, and not a regular function Index : This array can store strings and any object but their index will be prepresented by numbers. By default array index starts from zero.
Multidimensional : In this case an array element can contain another array as a value, which in turn can hold other arrays as well. In such a way you can create multidimensional array( two-dimensional or three-dimensional array) .
Operators are used to manipulate or perform operations on variables and values.There are many operators used in PHP . Such as :-
Ternary Operator :
* It is called the ternary operator because it works with three operands.a condition, a result for true, and a result for false
* Ternary operator is a shorthand way of doing if statements.
++$a - Pre-increment: Increments $a by one, then returns $a
$a++ - Post-increment: Returns $a, then increments $a by one
--$a - Pre-decrement: decrements $a by one
$a-- - Post-decrement: Returns $a, then decrements $a by one
String :(.,.=)
. - Concatenation operator: which returns the concatenation of its right and left arguments.
.= - concatenating assignment operator: which appends the argument on the right side to the argument on the left side
Control structures are the block of codes that dictate the flow of control.
* if/else/elseif:
* while:
* do while:
* for:
* foreach:
* switch:
Questions
a)What will be the output ?
$ch = 1;
switch($ch){
case 1:echo "a";
echo "b";
case 2:echo "c";
default:echo "d";
}
b)What will be the output ?
$ch = 1;
switch($ch){
case 1: echo "a";
echo "b";
break;
case 2: echo "c";
break;
default:echo "d";
}