Search This Blog

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




Share Links

Related Posts Plugin for WordPress, Blogger...