Reply to Re: Array pointer for internal(?) functions

Your name:

Reply:


Posted by Mladen Gogala on 01/12/06 05:48

On Thu, 12 Jan 2006 03:45:30 +0100, André Hänsel wrote:

> function foo()
> {
> $a = array('a' => 'b', 'c' => 'd');
> return array_keys($a);
> }
> while ($a = each(foo()))
> {
> echo 'dummy';
> }


Andre, the problem is not in the pointer, the problem is in the
loop. The function foo() will be called each time the loop condition
is checked, producing always a new array and a new set of keys.
Here is a code that does work:
$ cat /tmp/ttt;
<?
function foo() {
$a = array('a' => 'b', 'c' => 'd');
return array_keys($a);
}
$b=foo();
while ($a = each($b))
{
echo "dummy\n";
}
?>
$ php /tmp/ttt
dummy
dummy

--
http://www.mgogala.com

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация