Google+ PHP TUTORIALS ONLINE HELP FOR MEDICAL AND PROGRAMMING: PHP Data Types

Tuesday 18 February 2014

PHP Data Types

PHP Data Types

Today i will teach you. how we can use PHP data types.
There are Seven types of PHP Data Types.
  1. String.
  2.  Integer.
  3.  Floating point numbers,
  4.  Boolean.
  5.  Array.
  6.  Object.
  7.  NULL.
String Data type:-The string is a sequence of characters. we can be any text inside quotes. we have used single or double quotes. you can see below in examples
Example of String Data types:-
<html>
<head>
<title>String data type</title>
</head>
<body>
<?php 
$x= "Hello PHP";
$y= "Welcome to PHP";
echo $x;
echo "<br>";
echo $y;
?>
</body>
</html>
Output
Hello PHP
Welcome to PHP
 Integer Data type:-Integer is a basic data types. We can assign which has no of fractional part to int type but int is a 2 Byte space.
Importants Rules:
Integer is a least one digit (0-9).
Integer cannot contain comma or blanks.
Integer must not have a decimal point.
Integer can be either positive or negative values.
Now we can assign a value between the above range below example. In this example we have used different variables like as negative number, hexadecimal number ,octal numbers and we have used PHP var_dump(); function returns the data type.
Example
<html>
<head>
<title>Integer Data types</title>
</head>
<body>
<?php 
$y = 4567;
var_dump($y);
echo "<br>"; 
$y = -254; // negative number 
var_dump($y);
echo "<br>"; 
$y = 0x8C; // hexadecimal number
var_dump($y);
echo "<br>";
$y = 047; // octal number
var_dump($y);
?> 

</body>
</html>
Output
int(4567)
int(-254)
int(140)
int(39)

No comments:

Post a Comment