I've thought about this problem before but never got anywhere on it. I think I've done it with Python but never PHP.
Define a basic php array:
$arr = array (array(1,2,3), array(4,5,6), array(7,8,9));
Then run this snippet:
foreach ($arr as $row)
{
list($a, $b, $c) = $row;
echo "$a, $b, $c <br>";
}
This is so common, I must have done it a million times during my php career...but it seems a bit wasteful. $row is a temp variable and is never really used and the list()= line seems like it should be able to be put into the foreach bracket
Something like this (of course, this doesn't work):
foreach ($arr as list($a, $b, $c) = $row)
{
echo "$a, $b, $c <br>";
}
Neither does:
foreach ($arr as list($a, $b, $c))
{
echo "$a, $b, $c <br>";
}
Has anyone come up with a cool shortcut for this? Thanks!