Skip to content

Instantly share code, notes, and snippets.

@rurtubia
Last active November 8, 2015 13:52
Show Gist options
  • Select an option

  • Save rurtubia/46d6996ad636f2bc8a82 to your computer and use it in GitHub Desktop.

Select an option

Save rurtubia/46d6996ad636f2bc8a82 to your computer and use it in GitHub Desktop.
PHP data types
<?php
//An array stores multiple values in one single variable.
//In the following example $cars is an array
$cars = array("Volvo","BMW","Toyota");
//The PHP var_dump() function returns the data type and value:
var_dump($cars);
?>
<?php
//A boolean represents two possible states: TRUE or FALSE.
$x = true;
$y = false;
//Booleans are often used in conditional testing.
?>
<?php
//a number with a decimal point or a number in exponential form.
$x = 10.365;
//The PHP var_dump() function returns the data type and value:
var_dump($x);
?>
<!DOCTYPE HTML>
<HTML>
<BODY>
<?php
//PHP Integers:
# Range: -2,147,483,648 to +2,147,483,647
# must have at least one digit (0-9)
# cannot contain comma or blanks
# must not have a decimal point
# can be either positive or negative
# can be specified as:
# decimal (10-based)
# hexadecimal (16-based - prefixed with 0x)
# octal (8-based - prefixed with 0)
$x = 5985;
//The PHP var_dump() function returns the data type and value
var_dump($x);
?>
</BODY>
</HTML>
<?php
//Null is a special data type which can have only one value: NULL.
//A variable of data type NULL is a variable that has no value assigned to it.
//Tip: If a variable is created without a value, it is automatically assigned a value of NULL.
$x = "Hello world!";
//Variables can also be emptied by setting the value to NULL:
$x = null;
var_dump($x);
?>
<?php
//object is a data type which stores data and information on how to process that data.
//In PHP, an object must be explicitly declared.
//First we must declare a class of object.
# For this, we use the class keyword.
#A class is a structure that can contain properties and methods:
class Car {
function Car() {
$this->model = "VW";
}
}
// create an object
$herbie = new Car();
// show object properties
echo $herbie->model;
?>
<!DOCTYPE HTML>
<HTML>
<BODY>
<?php
#sequence of characters.
#A string can be any text inside quotes.
#You can use single or double quotes:
$string1 = "hello World!";
$string2 = 'bye World!';
echo ("$string1");
echo ("<br>");
echo ("$string2");
?>
</BODY>
</HTML>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment