PHP foreach(...)问题

I was wondering if using

foreach(get_some_array() as $boo) do_something...

is slower than

$arr = get_some_array();
foreach($arr as $boo) do_something...

I mean would get_some_array() be called like 10000000 times if the array would have so many elements (in the 1st example) ?

No, that function will be called just 1 time. You can verify this by doing:

<?php
function get()
{
    echo "getting
";

    return array('a', 'b', 'c', 'd');
}

foreach (get() as $v) {
    echo $v . "
";
}
?>

Here it outputs:

murilo@mac:regionais$ php -f teste.php 
getting
a
b
c
d

$arr = get_some_array(); theoretically adds zero time to this equation, so it really wont make a difference what you use here.