Home | | Computer Application 12th Std | PHP Data Type

PHP (Hypertext Pre-Processor) - PHP Data Type | 12th Computer Applications : Chapter 4 : Introduction to Hypertext Pre-Processor (PHP)

Chapter: 12th Computer Applications : Chapter 4 : Introduction to Hypertext Pre-Processor (PHP)

PHP Data Type

PHP scripting language supports 13 primitive data types. 1. String 2. Integer 3. Float 4. Boolean 5. Array 6. Object 7. NULL 8. Resource

PHP Data Type

PHP scripting language supports 13 primitive data types. Data Types playimportant role in all programing languages to classify the data according to the logics. PHP supports the following data types.

1. String

2. Integer

3. Float

4. Boolean

5. Array

6. Object

7. NULL

8. Resource


String:

String is a collection of characters within the double or single quotes like

“Computer Application” or ‘Computer Application’. Space is also considered as a character.

Example:

<?php

$x = “Computer Application!”;

$y = ‘Computer Application’;

echo $x;

echo “<br>”;

echo $y;

?>


Integer:

Integer is a data type which contains non decimal numbers.

Example:

<?php

$x = 59135;

var_dump($x);

?>


Float:

Float is a data type which contains decimal numbers.

Example:

<?php

$x = 19.15;

var_dump($x);

?>


Boolean:

Boolean is a data type which denotes the possible two states, TRUE or FALSE

Example:

<?php

$x = true;

$y = false;

echo $x;

echo $y;

?>


Array:

Array is a data type which has multiple values in single variable. You will learn about arrays in the next chapter.

Example:

<?php

$cars = array(“Computer”,”Laptop”,”Mobile”);

var_dump($cars);

?>

OUTPUT:

array(3) { [0]=> string(5) “Computer “ [1]=> string(3) “Laptop “ [2]=> string(6) “Mobile “ }


Var_dump:

The var_dump() system define function, returns structured information (type and value) about variables in PHP.


Object:

In PHP object is a data type which contains information about data and function inside the class.

<?php

class School {

function marks() {

$this->sec = “A”;

}

}

// create an object

$school_obj = new School ();

//show object properties

echo $school_obj ->sec;

?>


NULL:

Null is a special data type which contains no value:

<?php

$x = “COMPUTER APPLICATION!”;

$x = null;

var_dump($x);

?>

OUTPUT:

NULL


Resources

Resource is a specific variable, it has a reference to an external resource. These variables hold specific handlers to handle files and database connections in respective PHP program.

<?php

// Open a file for reading

$handle = fopen(“note.txt”, “r”);

var_dump($handle);

echo “<br>”;

 

//Connect to MySQL database server with default setting

$link = mysql_connect(“localhost”, “root”, “”);

var_dump($link);

?>

Tags : PHP (Hypertext Pre-Processor) , 12th Computer Applications : Chapter 4 : Introduction to Hypertext Pre-Processor (PHP)
Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
12th Computer Applications : Chapter 4 : Introduction to Hypertext Pre-Processor (PHP) : PHP Data Type | PHP (Hypertext Pre-Processor)


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.