In PHP 5.5, we have a new feature, which is to use list
together with foreach
.
$array = [
[1, 2],
[3, 4],
];
foreach ($array as list($a, $b)) {
echo "A: $a; B: $b\n";
}
Output is:
A: 1; B: 2
A: 3; B: 4
I understand very well what happens in the call of this foreach
, but I would like to know how this can bring benefits in the "real life programming", since the examples in the PHP Manual are always too simple. / p>
What are the benefits of having a foreach
with list
? I would like some examples to set the idea.