You are here: Re: Why does this foreach loop fail to work? « PHP Programming Language « IT news, forums, messages
Re: Why does this foreach loop fail to work?

Posted by comp.lang.php on 09/22/06 14:29

Tim Roberts wrote:
> "comp.lang.php" <phillip.s.powell@gmail.com> wrote:
> >
> >[PHP]
> > $array = array($firstOrderByFieldIfClause, $groupByClause,
> >$orderByClause);
> > array_walk($array, create_function('&$a', '$a = substr($a, 0,
> >strrpos(trim($a), ",")); if ($a) $a = ", $a";'));
> > print_r("firstOrderByFieldIfClause = $firstOrderByFieldIfClause and
> >groupByClause = $groupByClause and orderByClause = $orderByClause<P>");
> >[/PHP]
> >
> >Upon execution the fields within $array are never changed (verified by
> >checking code), and I don't understand why.
>
> It certainly does. Try "var_dump($array);", and you'll see that all three
> strings were changed.
>
> Your mistake is in thinking that changes to $array(0) will also affect
> $firstOrderByFieldIfClause.
>
> The array constructor makes three new strings.

I should have figured that all complex objects that take parameters
make clones of the parameters unless passed by reference. So that's
what I did:

$array = array(&$firstOrderByFieldIfClause, &$groupByClause,
&$orderByClause);

That did the trick, thanx!
Phil

> --
> - Tim Roberts, timr@probo.com
> Providenza & Boekelheide, Inc.

 

Navigation:

[Reply to this 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

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