June 2017
Intermediate to advanced
536 pages
9h 49m
English
The PHP arrays are the most frequent collection structure used in PHP. We can squeeze pretty much anything into an array, ranging from scalar values to objects. Iterating through elements of such a structure is trivially easy using the foreach statement. However, arrays are not the only iterable types, as objects themselves are iterable.
Let's take a look at the following array-based example:
<?php$user = [ 'name' => 'John', 'age' => 34, 'salary' => 4200.00];foreach ($user as $k => $v) { echo "key: $k, value: $v" . PHP_EOL;}
Now let's take a look at the following object-based example:
<?phpclass User{ public $name = 'John'; public $age = 34; public $salary = 4200.00;}$user = new User();foreach ($user as $k => $v) { echo ...Read now
Unlock full access