3
In PHP 5.5, we have a new feature, which is to use list
together with the foreach
.
$array = [
[1, 2],
[3, 4],
];
foreach ($array as list($a, $b)) {
echo "A: $a; B: $b\n";
}
Exit is:
A: 1; B: 2
A: 3; B: 4
I understood very well what happens in the flame of this foreach
, but I would like to know how this can bring benefits in the "real life of programming", because the examples of the PHP Manual are always too simple.
What are the benefits brought by being able to accomplish a foreach
with list
? I would like some examples to fix the idea.