PHP KEYWORDS
There are 24 keywords in php. php keywords are case sensetive. the following php keywords are
- break
- case
- catch
- do
- class
- function
- elseif
- public
- throw
- for
- endfor
- extends
- if
- new
- static
- try
- exception
- while
- endwhile
- exit
- else
- or
- switch
- var
PHP DATATYPES
there are 8 datatype in php as follow
- integer
- float
- string
- boolean
- null
- resource
- array
- object
- SCALAR DATATYPE - integer, float, string, boolean.
- SPECIAL DATATYPE - null, resource.
- COMPOUND DATATYPE - array,object.
1. INTEGER
An integer data type is a non decimalnumber for e.g-
<?php
$a=10;
var_dump($a);
?>
output - int 10
2. FLOAT
Float ia a number with decimal point for e.g-
<?php
$a=10.5;
var_dump($a);
?>
output - float 10.5
3. STRING
A string is a sequence of character. A string can be any type inside codes either double code or single code. for e.g-
<?php
$a='hello';
var_dump($a);
?>
output - string hello
OR
<?php
$a="hello"
var_dump($a);
?>
output - string hello
there are four type of string in php follow as-
1.single qouted string
In this string the string enclosed with single code.
<?php
$a='hello';
var_dump($a);
?>
2.double qouted string
in this string the string enclosed with double code.
<?php
$a="hello";
var_dump($a);
?>
3.heredoc
In this string the string use multiline string with double code.
2. FLOAT
<?php
$a=10.5;
var_dump($a);
?>
output - float 10.5
<?php
$a='hello';
var_dump($a);
?>
output - string hello
OR
<?php
$a="hello"
var_dump($a);
?>
output - string hello
<?php
$a='hello';
var_dump($a);
?>
in this string the string enclosed with double code.
<?php
$a="hello";
var_dump($a);
?>
<?php
$a="hello how are you i am fine what about you";
var_dump($a);
?>
4.nowdoc
In this string the string use multiline string with single code.
<?php
$a='hello how are you i am fine what about you';
var_dump($a);
?>
4. BOOLEAN
A boolean represent two possible states either true or false. for eg-
<?php
$a=10;
if($a%2==0)
{
true;
}
else
{
false;
}
?>
output - true
5. NULL
Null is a special datatype which can have only one values that is null. and if a variable is created without the value it is automatically assigned a value null. for e.g-
<?php
$a='hello how are you i am fine what about you';
var_dump($a);
?>
<?php
$a=10;
if($a%2==0)
{
true;
true;
}
else
else
{
false;
false;
}
?>
?>
output - true
<?php
$a=Null;
var_dump($a);
?>
output - Null
OR
<?php
$a="";
var_dump($a);
?>
output - Null
6. RESOURCE
A resource is a not actual data type it is use for storing a refference to a function.
7. ARRAY
An array stores multiple values in one single variable. for eg-
<?php
$cars=Array("bmw","alto","swift","audi";
var_dump($cars);
?>
output - array([0]=>bmw,[1]=>alto,[2]=>swift,[3]=>audi)
In php there are two types of array -
1. Index array
In index array only have values.
<?php
$cars=Array("bmw","alto","swift","audi";
var_dump($cars);
?>
output - array([0]=>bmw,[1]=>alto,[2]=>swift,[3]=>audi)
2.Associative arry
In associative array have key and values.
<?php
$cars=array([0]=>bmw,[1]=>alto,[2]=>swift,[3]=>audi)
var_dump($cars);
?>
output - array([0]=>bmw,[1]=>alto,[2]=>swift,[3]=>audi)
8. OBJECT
object is a real word entity. it is blue print of class. it is used access to the class. for eg-
<?php
class demo
{
Function Display()
{
$a='hello';
var_dump($a);
}
}
$d=new demo();
$d=>display() ;
?>
<?php
$a="";
var_dump($a);
?>
output - Null
<?php
$cars=Array("bmw","alto","swift","audi";
var_dump($cars);
?>
output - array([0]=>bmw,[1]=>alto,[2]=>swift,[3]=>audi)
In php there are two types of array -
1. Index array
In index array only have values.
<?php
$cars=Array("bmw","alto","swift","audi";
var_dump($cars);
?>
output - array([0]=>bmw,[1]=>alto,[2]=>swift,[3]=>audi)
2.Associative arry
In associative array have key and values.
<?php
$cars=array([0]=>bmw,[1]=>alto,[2]=>swift,[3]=>audi)
var_dump($cars);
?>
output - array([0]=>bmw,[1]=>alto,[2]=>swift,[3]=>audi)
8. OBJECT
object is a real word entity. it is blue print of class. it is used access to the class. for eg-
<?php
class demo
{
Function Display()
Function Display()
{
$a='hello';
$a='hello';
var_dump($a);
}
}
$d=new demo();
}
$d=new demo();
$d=>display() ;
?>
0 Comments