PHP Data Type
Subject: Web development using PHP and MySQL
Variables can store or hold data of different types such as String, Integer, Float or double, Boolean, Array.
String is a sequence of characters or any text inside single or double quotes.
Example 1
<?php
$name="Ben Onuorah";
$msg="Welcome to my site";
print "$name <br/> $msg";
?>
Integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.
Example 2
<?php
$price=15000;
?>
Float is a number with a decimal point or in exponential form.
Example 3
<?php
$discount=50.5;
?>
Boolean represents two (true or false) states.
Example 4
<?php
$even_number=true;
?>
Array is use to stores multiple values in one variable for easy access and manipulation.
Example 5
<?php
$ng_states = array("Anambra","Edo","Kaduna","Lagos");
?>
What is my variable data type?var_dump() can be use to know the data type of a variable
Example 6
<?php
//array holding student name, age, height, married
$student = array(“Benâ€, 35, 5.6, true);
//var_dump() function returns data type and value
var_dump($student);
?>
By:
Benjamin Onuorah
Login to comment or ask question on this topic
Previous Topic Next Topic