php Data Types – II

PHP as Array

An array is used to store multiple values in a single variable.

Let’s see with an example:-

<?php 
$techalltype= array("html","php","dotnet");
var_dump($cars);
?>

Output:-

array(3) { [0]=> string(4) “html” [1]=> string(3) “php” [2]=> string(6) “dotnet” }

explanation:-

array(3) – it means array contain 3 variables

[0]=> string(4) “html” – it means at  index [0]=> string(4) variable length is 4, and that is “html”.

Note:- An array count the variable from index[0].

PHP as Object:- 

An object is stores data and information to process that data.

In order to use php as object we need to declare a class of object, by class keyword. Then use class as a structure which can contain properties and methods.

Let’s see with an example:-

<?php
class techall {
function techall() {
$this->techtype = "TECHALLTYPE";
}
}

$alltechtype = new techall();     // create an object by using new keyword


echo $alltechtype->techtype; // Display object properties
?>

Output:-

TECHALLTYPE

PHP NULL Value:-

Null is a data type which can have only one and that is NULL value, no other value assigned to it.

Let’s see with an example:-

<?php
$x = "Welcome to Tech all type";
$x = null; // $x now assigned Null Value
var_dump($x);
?>

Output:-

NULL

I am Hitesh from Jamshedpur (India). I have been working as a Web Application Developer from last 4+ years. I love diverse and attention catching web presence for a variety of users. Also I love to learn new things in Web Development.

Tags: , , ,