PHP HOME
PHP Introduction
PHP SETUP
PHP Syntax
PHP Data Types
PHP Outputs
PHP Variable
PHP Constant
PHP Strings
PHP Operators
PHP if else if
PHP Switch
PHP while loop
PHP for loop
PHP Arrays
PHP Functions
PHP Sorting Array
PHP Form Handling
PHP Form Validation
PHP Form Required
PHP Form URL/EMAIL
PHP Form Submit
PHP Contact Form
PHP DATE & TIME
PHP INCLUDE
PHP FILE HANDLING
PHP FILE OPEN/READ
PHP FILE CREATE/WRITE
PHP FILE UPLOAD
PHP SESSION
PHP COOKIES
PHP FILTER
PHP ERROR HANDLING
PHP EXCEPTION
PHP Redirects
PHP with MySQL
PHP WITH MYSQL DB
MYSQL CONNECT
MYSQL CREATE DATABASE
SELECT DATABASE
MYSQL CREATE TABLE
MYSQL INSERT DATA
MYSQL SELECT DATA
MYSQL UPDATE DATA
MYSQL DELETE DATA
MYSQL ORDER
MYSQL LIMIT
MYSQL LAST ID
PHP variables do not need to be declared before the assignment, it is declared at the time of assignment by the leading of dollar sign ($). PHP variables can store different types of data, there is no need to declared data types before or at the time of assignment.
There are eight data types in PHP
- Strings
- Integers
- Float or Doubles
- Booleans
- Null
- Array
- Objects
- Resources
How many data types in PHP?
There are eight data types in PHP such as Strings, Integers, Float or Doubles, Booleans, Null, Array, Objects, Resources.
<!DOCTYPE html>
<html>
<body>
<?php
$string-1 = "Hello John!";
$string-2 = 'String can contain 39 charecter';
echo $string-1;
echo $string-2;
?>
</body>
</html>
The above code produces the following results
Outputs: Hello John! String can contain 39 characters
An integer must start from -2,147,483,647 and end at 2,147,483,647
<!DOCTYPE html>
<html>
<body>
<?php
$a = 357;
$b = -753;
echo $a;
echo $b;
var_dump($a);
?>
</body>
</html>
The above code produces the following results
Outputs: 357 -357 int(357)
The PHP var_dump function return also data types
<!DOCTYPE html>
<html>
<body>
<?php
$a = 3.57;
echo $a;
var_dump($a);
?>
</body>
</html>
The above code produces the following results
Outputs: 3.57 float(3.57)
<!DOCTYPE html>
<html>
<body>
<?php
$a = TRUE;
$b = FALSE;
if($a){
echo "TRUE";
}
if(!$b){
echo "FALSE";
}
?>
</body>
</html>
The above code produces the following results
Outputs: TRUE FALSE
The PHP var_dump function return also data types
<!DOCTYPE html>
<html>
<body>
<?php
$a = "Hello John!";
$a = null;
var_dump($a);
?>
</body>
</html>
The above code produces the following results
Outputs: NULL
The PHP var_dump function return also data types
<!DOCTYPE html>
<html>
<body>
<?php
$fruits = array('apple', 'banana', 'mango');
var_dump($fruits);
?>
</body>
</html>
The above code produces the following results
Outputs: array(3) { [0]=> string(5) 'apple' [1]=> string(6) 'banana' [2]=> string(5) 'mango' }
Example of Objects
<!DOCTYPE html>
<html>
<body>
<?php
class fruits
{
function best_fruit()
{
echo "Mango.";
}
}
$object = new foo;
echo $object->best_fruit();
?>
</body>
</html>
The above code produces the following results
Outputs: Mango