Integers and Floats
Account number: 71722091Balance: £12000
Booleans
This section should be fairly empty, since $sectionBoolean
is set to:bool(false)
Set it to true
and this section will expand
Arrays
Let us echo and var_dump our array $names[]
, currently empty:
Array
array(2) {
[0]=>
string(5) "David"
[1]=>
string(4) "Mary"
}
echo $names[1]
returns: Mary
We have a multi-dimensional array
array(2) {
[0]=>
array(3) {
["username"]=>
string(4) "Korv"
["email"]=>
string(13) "km@korvin.org"
["likes"]=>
array(2) {
[0]=>
string(7) "history"
[1]=>
string(4) "food"
}
}
[1]=>
array(3) {
["username"]=>
string(4) "Mary"
["email"]=>
string(16) "mary@hotmail.com"
["likes"]=>
array(2) {
[0]=>
string(5) "books"
[1]=>
string(4) "cats"
}
}
}
Let's see if we can access the second user's email.
mary@hotmail.com
Now let's use a foreach
loop over the $users
array.
Korv Mary
We could use the same technique to output the list of email addresses:
km@korvin.org mary@hotmail.com
and likes?
history,food books,cats
Now lets add a new user
and modify a record.
Users:
Korv Mary Jeremy
Likes:
history,food books,PHP reading,cooking
Null
Null represents a variable with no value; the variable has either been set to NULL, has been unset, or has never been set in the first place.
Earlier we set $noName
to null. Let's var_dump($noName)
:
NULL
Now let's set and echo
the variable: Name
Now let's unset
and var_dump
the variable: NULL
Now let's set the variable back to NULL, since that's best practice: NULL
Concatenation and Variable Parsing
The current weather is rainy and it's 30.6 degrees
The current weather is rainy and it's 30.6 degrees.
The current weather is rainy and it's 30.6°