Creating (Declaring) PHP Variables
In PHP, a variable starts with the $ sign, followed by the name of the variable:
1 2 |
$x = 5; $y = "John" |
In the example above, the variable $x will hold the value 5, and the variable $y will hold the value “John”.
Note: When you assign a text value to a variable, put quotes around the value.
Note: Unlike other programming languages, PHP has no command for declaring a variable. It is created the moment you first assign a value to it.
PHP – Using Iterables
The iterable keyword can be used as a data type of a function argument or as the return type of a function:
1 2 3 4 5 6 7 8 9 10 |
<?php function printIterable(iterable $myIterable) { foreach($myIterable as $item) { echo $item; } } $arr = ["a", "b", "c"]; printIterable($arr); ?> |