PHP Data Types

PHP Data Types:

PHP variables stores data in the different data form some are in numeric or some in alphabets. According to Wikipedia data type is a set of values. PHP data types has several data types.We will discuss all types step by step. 

  1. String 
  2. Integers 
  3. Floating point numbers
  4. Boolean
  5. Array
  6. Object
  7. NULL

1. PHP Strings

As we read previous lesson about strings exactly same thing happen here. We can say string could be a text like “Hello World” In other words strings is a sequence of alphabets/characters. Remember put quotes around the text/character.We simply assign a text value to variable to explain strings. Let’s take example.

php
$x="Knowledge idea";
echo $x;
$x='Knowledge idea';
echo $x;
?>

we could be use double quotes or single quotes around the characters in strings  result will be same.

2. PHP Integers

Integers are whole numbers, without decimal point. Integers similar to the whole numbers.Integers could be positive or negative.Integers can be written in three formats.

  • Decimal
  • Hexadecimal 
  • Octal

Let’s take the following example to express the Integers.

php
// var_dump() return the data type and variable value
$x= 1234; //Positive Numeric Value 
var_dump($x);
echo 
$y= -1234; // Negative Numeric Value 
var_dump($y);
echo 
$z= 0x1234; // hexadecimal number
var_dump($z);
echo 
$v= 01234; // octal number
var_dump($v);
echo 
?>

3. Floating Point Numbers

Floating point number is the number in which decimal point exist. In C floating point numbers are corresponding to the double data type. PHP admit two types of floating point numbers. Literal number with decimal point and other is with scientific notation. Like as 9.85D-6. Let’s take the next floating point number example.

php
// var_dump() return the data type and variable value
$x= 1.234; // with Literal Numeric value 
var_dump($x);
echo 
;
$y= 1.2D4; // with Scientific Notation
var_dump($y);
echo 
;
$z= 2E-4; // with Scientific Notation 
var_dump($z);
echo 
;
?>

4. PHP Boolean

Boolean have two values either  True or False. Take following example.

php
$p= True;
$q= False;

// Take test example which is most usage in programming if/else
   structure

if (True)
   print{"You are beautiful"};
else 
   print{"You are not beautiful"}

// with False

if (False)
   print{"You are beautiful"};
else 
   print{"You are not beautiful"}
?>

5. PHP Array

Array have multiple/group of values in single variable.Array values are related data components.

php
$Country=array('America','England','Japan');
echo $Country;

// Take test with array position

$data[0]= "John is Funny";
$data[1]= "John is Rude";
$data[2]= "John is Rock";
$data[3]= "John is cute";
?>

As you seen above we describe array appoint a value to array position by specifying which array element you want to appoint a value.

6. PHP Objects

PHP Object is a data type which may store info and data.Object  Information and data need absolutely declared. In the beginning of object we declare class and assign a keyword related to his class. And class is a frame that consist of properties and methods. 

7. PHP NULL

The special NULL value show that a variable has no value. NULL is the only possible value PHP data type NULL. The NULL value diagnose in case a variable is blank/empty. 

php
$a="Knowledge idea";
$a= NULL;
// var_dump() return the data type and variable value
var_dump($a);
?>

Grab/copy to clipboard all over these PHP data types codes above and practice as yourself — If make any error you may discuss on comments & feedback.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments