[wp-hackers] Perhaps OT PHP Question

Sam Angove sam at rephrase.net
Tue May 29 01:34:52 GMT 2007


On 5/29/07, Chris Williams <chris at clwill.com> wrote:
>
> On my local test machine (php 5.2, wp 2.2) it works perfectly.  On the
> server (php 4.?, wp 2.2) it doesn't.  The $categories array is unchanged.

PHP 5 made changes to variable references. The loop isn't working
because you're changing the cat_name on a copy of the category, then
leaving that copy to be thrown away when the loop ends.

For my money the simplest workaround is this:

foreach ($categories as $key => $category) {
   $categories[$key] = "whatever";
}

But there are half a dozen other options. Try the `foreach` page in
the manual if you want more.


More information about the wp-hackers mailing list