Datatype :

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
Syntax bool is_bool ( mixed var)
It retuns true if the variable is booleans.

Integer :
is_int() -- Find whether a variable is an integer
Syntax bool is_int ( mixed var)
It return true if the variable is integer.

Float :
is_float() -- Finds whether a variable is a float
Syntax bool is_float ( mixed var)
It return true if the variable is float.

String :
is_string() -- Finds whether a variable is a string
Syntax bool is_string ( mixed var)
It return true if the variable is string.

Array :
is_array() -- Finds whether a variable is an array
Syntax bool is_array ( mixed var)
It returns true if the variable is array.

array()

is a language construct used to represent arrays, and not a regular function
Syntax array(key => values)
Index :
This array can store strings and any object but their index will be prepresented by numbers. By default array index starts from zero.
example:
  	
<?php
$array = array(1, 3, 5, 2,  8);
print_r($array);
?>
		
Output :
Array ( [0] => 1 [1] => 3 [2] => 5 [3] => 2 [4] => 8 )
Associative :
In an associative array a key is associated with a value.
example:
  	
<?php
$arr=array("Brussels"=>"Belgium","Paris"=> "France","Berlin"=> "Germany");
print_r($arr);
?>
		
Output :
Array ( [Brussels] => Belgium [Paris] => France [Berlin] => Germany )
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) .
example:
  	
<?php
$shop = array( array("rose", 1.25 , 15),
              array("daisy", 0.75 , 25),
              array("orchid", 1.15 , 7)
              );
print_r($shop);
?>
		
Output :
Array ( [0] => Array ( [0] => rose [1] => 1.25 [2] => 15 ) [1] => Array ( [0] => daisy [1] => 0.75 [2] => 25 ) [2] => Array ( [0] => orchid [1] => 1.15 [2] => 7 ) )

Operator :

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.
example:
  	
<?php
$age = 23;
$agestr = ($age <= 16) ? 'child' : 'adult';
print $agestr;
?>
		
Output :
adult

Arithmatic :(+,-,*,/,%)

Assignment :(=, +=, -=, *=, /=, %=)
example:
  	
<?php
  $a=6;
  $a+=10 ;   //i.e $a=$a+10
  $a-=2  ;    //i.e $a=$a-2
  $a*=3 ;     //i.e$a=$a*3
  $a/=5  ;    //i.e$a=$a/5
?>
		

Comparision :(==, !=, >, <, >=, <=)

These operator are used in contol structure


Increment / Decrement :(++,--)

These operator are used in contol structure

example:
  	
++$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

example:
  	
<?php
$a = "Hello ";
$b = $a . "World!"; // now $b contains "Hello World!"
$a = "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
		
Array :(+)
example:
  	
<?php
$a = array("a" => "apple", "b" => "banana");
$b = array("a" => "pear", "b" => "strawberry", "c" => "cherry");
$c = $a + $b;
print_r($c);
?>
		
Output :
Array ("a"=>"apple","b"=>"banana","c"=>"cherry")

Control Structure :

Control structures are the block of codes that dictate the flow of control.


* if/else/elseif:
Syntax if(cond){
       Statement;
}elseif(cond){
      Statement;
}else{
}

* while:
Syntax while(cond){
       Statement;
}

* do while:
Syntax do{
      Statement;
}
while(cond);

* for:
Syntax for(initialisation;comparision;icrement/decrement){
      Statement;
}

* foreach:
Syntax foreach($arr as $key => $ value){
      Statement;
}

* switch:
Syntax switch(arg){
Case 'val0':
      statement;
      Break;
Case 'val1':
      statement;
      Break;
Default:
      statement;
      Break;
}

Questions

  1. 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";
    }