array data types and object data types are comes under this category
Showing posts with label data types. Show all posts
Showing posts with label data types. Show all posts
special data types in php
resource data types and null data types
resource data types refers the external resources like data connection , file pointer , FTP connection ...ect
<?php
mysql_connect("hostname",username","password");
?>
<?php
$con=mysql_connect("hostname",username","password");
echo $con;
?>
here con is external resource type
output : resource #id2
null data type
null is not a value
the variable not initialized with any value
the variable initialized with null value
if the value of the variable is removed using unset function
based on by that 3 conditions we consider a variable has null value
<?php
$a=100;
unset($a);
echo is_null($a);
?>
output : 1
if is it null returns 1 else returns nothing
resource data types refers the external resources like data connection , file pointer , FTP connection ...ect
<?php
mysql_connect("hostname",username","password");
?>
<?php
$con=mysql_connect("hostname",username","password");
echo $con;
?>
here con is external resource type
output : resource #id2
null data type
null is not a value
the variable not initialized with any value
the variable initialized with null value
if the value of the variable is removed using unset function
based on by that 3 conditions we consider a variable has null value
<?php
$a=100;
unset($a);
echo is_null($a);
?>
output : 1
if is it null returns 1 else returns nothing
scalar data types in php
boolean , integer , float,string are scalar data types in php
boolean : it holds boolean values
"true" returns 1 and "false" does not returns any value.
<?php
$a=true;
echo $a;
?>
output : 1
is_bool(x) checks is it bool or not , if bool then return 1 else it is nothing anything
<?php
$a=true;
echo (bool)$a;
?>
output :1
<?php
$a=false;
echo (bool)$a;
?>
output : 1
<?php
$a=5;
echo (bool)$a;
?>
output :
nothing above display , because it is not a boolean value . So, false return . So, onthing to display
integer : it holds integer values
<?php
$a=5;
echo $a;
?>
output : 5
to convert input value into integer datatype we use "is_int"
<?php
$a=100;
echo is_int($a);
?>
output : 1
<?php
$a='world';
echo is_int($a);
?>
output :
at above nothing is display
reason : "world" is not an integer
So, false returned
float : it holds floating point value
<?php
$a=10.8;
echo $a;
?>
output : 10.8
string : it holds string value
<?php
$a="world";
echo $a;
?>
output : world
<?php
$a="world";
$atr="welcome to $a";
echo $atr;
?>
output : welcome to world
<?php
$a="world";
$atr="welcome to $a".'<br>'; // here <br> for new line
$atr='welcome to $a';
echo $atr;
echo 'atr1;
?>
output :
welcome to world
welcome to $a
boolean : it holds boolean values
"true" returns 1 and "false" does not returns any value.
<?php
$a=true;
echo $a;
?>
output : 1
is_bool(x) checks is it bool or not , if bool then return 1 else it is nothing anything
<?php
$a=true;
echo (bool)$a;
?>
output :1
<?php
$a=false;
echo (bool)$a;
?>
output : 1
<?php
$a=5;
echo (bool)$a;
?>
output :
nothing above display , because it is not a boolean value . So, false return . So, onthing to display
integer : it holds integer values
<?php
$a=5;
echo $a;
?>
output : 5
to convert input value into integer datatype we use "is_int"
<?php
$a=100;
echo is_int($a);
?>
output : 1
<?php
$a='world';
echo is_int($a);
?>
output :
at above nothing is display
reason : "world" is not an integer
So, false returned
float : it holds floating point value
<?php
$a=10.8;
echo $a;
?>
output : 10.8
string : it holds string value
<?php
$a="world";
echo $a;
?>
output : world
<?php
$a="world";
$atr="welcome to $a";
echo $atr;
?>
output : welcome to world
<?php
$a="world";
$atr="welcome to $a".'<br>'; // here <br> for new line
$atr='welcome to $a';
echo $atr;
echo 'atr1;
?>
output :
welcome to world
welcome to $a
Subscribe to:
Posts (Atom)