Variables
-
Resumo/Informações
-
Variables Types
- int, float string, boolean, array, etc...
-
Rules for PHP variable declaration
- Must start with the caracter "$".
- Can't be inicialized with "spaces" or numbers.
- Special caracters are not allowed (except "_").
-
Case Sensitive
- Allowed: $name, $Name, $NAME, $phone1, $phone_2
- Denied: $ address, $1phone, $número
- It is not required for you to specify what kind of variable it is, the PHP will identify it.
Examples:
-
Arrays
- 01: $variable_1 = 'Beans';
- 02: $shopping_list[1]='Beans;'
- 03: $shopping_list = array(1 => 'Beans', 2 => 'Arroz'...);
- 04: $shopping_list = array(
'1' => 'Beans',
'2' => 'Milk',
); - var_dump($shopping_list[1]); - Shows how many arrays there is and the string size for each.
- print_r($variable_1);
- echo $shopping_list[2];
- print $shopping_list[4];
1) When you don't know the array's position:
-
Multidimentional Arrays
-
$chess[8]['a'] = 'White King';
$chess[8]['b'] = 'White Queen';
$chess[7]['a'] = 'Black King';
$chess[7]['b'] = 'Black Queen';
print_r($tabuleiro);
> This will print an Array of Arrays (An Array with Arrays):
Array ([8] => Array ([a] => White King [b] => White Queen) [7] => Array ([a] => Black King [b] => Black Queen));
* Arrays of arrays.