PHP 8 - Data TypesLast modified: April 02, 2022
Variables can store data of different types. PHP support below Date Type
PHP is a loosely typed language; it does not have explicit defined data types, meaning if we define a variable as String first and then later we can later we can find as Integer given value support it. Here is an example of such logic.
- echo syntax is used to print code to the HTML/browser
<?php $five = '5'; $fiveNumber = 1 + $five; echo $fiveNumber; ?>
- PHP String
It can be any text withing " or ', single or double quotes for example, "Hello World"
<?php $name = "kafle"; $city = "London"; echo $name;<br /> echo $city; ?>
- PHP Integer
<?php $amount = 50000; echo $amount; ?>
- PHP Float
<?php $amount = 50000.59; echo $amount; ?>
- PHP Boolean
<?php $IsLondonInUK = true; echo $IsLondonInUK; ?>
- PHP Array
<?php $countries = array("HK", "UK", "USA"); var_dump($countries); echo "<br />"; echo "I live in "; echo $countries; ?>
- PHP Multidimensional Array
<?php $countries = array ( "Asia" => array("China", "Nepal", "India"), "Europe" => array("UK", "France"), ); print_r($countries); ?>
Constants are like variables except that once they are defined they cannot be changed or undefined.
<?php define("DBSERVER", "192.168.1.10"); echo DBSERVER; ?>