-
Notifications
You must be signed in to change notification settings - Fork 525
/
02_variables.php
56 lines (42 loc) · 1.35 KB
/
02_variables.php
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
<?php
/* ----- Variables & Data Types ----- */
/* --------- PHP Data Types --------- */
/*
- String - A string is a series of characters surrounded by quotes
- Integer - Whole numbers
- Float - Decimal numbers
- Boolean - true or false
- Array - An array is a special variable, which can hold more than one value
- Object - A class
- NULL - Empty variable
- Resource - A special variable that holds a resource
*/
/* --------- Variable Rules --------- */
/*
- Variables must be prefixed with $
- Variables must start with a letter or the underscore character
- variables can't start with a number
- Variables can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
- Variables are case-sensitive ($name and $NAME are two different variables)
*/
$name = 'Brad'; // String // Can be single or double quotes
$age = 40; // Integer
$hasKids = true; // Boolean
$cashOnHand = 10.5; //Float
var_dump($cashOnHand);
/* --- Adding variables to strings -- */
// Double quotes can be used to add variables to strings
echo "$name is $age years old";
// Better to do this
echo "${name} is ${age} years old";
// Concatenate Strings
echo '<h3>' . $name . ' is ' . $age . ' years old</h3>';
// Arithmetic Operators
echo 5 + 5;
echo 10 - 6;
echo 5 * 10;
echo 10 / 2;
// Constants - Cannot be changed
define('HOST', 'localhost');
define('USER', 'root');
var_dump(HOST);