How to iterate over an array of objects without foreach and ArrayAccess

Posted by kenny99 on Stack Overflow See other posts from Stack Overflow or by kenny99
Published on 2010-06-02T14:47:40Z Indexed on 2010/06/02 14:53 UTC
Read the original article Hit count: 253

Filed under:
|
|

Hi, I'm having to develop a site on PHP 5.1.6 and I've just come across a bug in my site which isn't happening on 5.2+. When using foreach() to iterate over an object, I get the following error: "Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference..."

Does anyone know how to convert the following foreach loop to a construct which will work with 5.1.6? Thanks in advance!

foreach ($post['commercial_brands'] as $brand)
                    {
                        $comm_food = new Commercial_food_Model;
                        $comm_food->brand = $brand;
                        $comm_food->feeding_type_id = $f_type->id;
                        $comm_food->save();
                    }

© Stack Overflow or respective owner

Related posts about php

Related posts about php5