In real-world application, we need to work with numbers, Booleans, strings and complex data. Php support variety of datatypes to represent different values.
Unlike other language (Ex: java, C), you no need to specify the type of data that this variable is going to hold, PHP handles this for us, this makes php a weakly typed language.
Example 1
$age = 23;
Variable ‘age’ holds numeric data.
Example 2
$name = "Krishna";
Variable ‘name’ holds string data.
Example 3
$male = true;
Variable ‘male’ holds Boolean data.
data_types_demo.php
#!/usr/bin/php
<?php
$age = 23;
$name = "Krishna";
$male = true;
echo "age is set to $age\n";
echo "name is set to $name\n";
echo "male is set to $male\n";
?>
Output
$./data_types_demo.php
age is set to 23
name is set to Krishna
male is set to 1
No comments:
Post a Comment