-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_variables.php
More file actions
57 lines (50 loc) · 1.21 KB
/
02_variables.php
File metadata and controls
57 lines (50 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
// What is a variable
// a variable is the name of memory location that hold data .in php variable declare with $
// Variable types
/*string
integer
float
boolean
array
object
null
*/
// Declare variables
$name = 'bikash';
$age = 20;
$isMale = true;
$height = 1.88;
$salary = null;
// Print the variables. Explain what is concatenation
echo $name . '<br>';
echo $age . '<br>';
echo $isMale . '<br>';
echo $height . '<br>';
echo $salary . '<br>';
// Print types of the variables
echo gettype($name) . '<br>';
echo gettype($age) . '<br>';
echo gettype($isMale) . '<br>';
echo gettype($height) . '<br>';
echo gettype($salary) . '<br>';
// Print the whole variable
var_dump($name, $isMale, $height, $age, $salary);
// Change the value of the variable
$name = true;
// Print type of the variable
echo gettype($name);
// Variable checking functions
is_string($name); //false
is_int($age); //true
is_bool($isMale); //true
is_double($height); //true
// Check if variable is defined
isset($name); //true
isset($address); //false
// Constants
define('PI', 3.14);
echo PI . '<br>';
// Using PHP built-in constants
echo SORT_ASC . '<br>';
echo PHP_INT_MAX . '<br>';