|
Posted by Rik on 02/07/07 16:00
Aggelos <djjelly@gmail.com> wrote:
>> function objects_from_array($var){
>> $return =3D array();
>> if(is_object($var)){
>> $return[] =3D $var;
>> }
>> if(is_array($var)){
>> $return =3D array_merge($return,objects_from_array($v=
ar));
Oops,
if(is_array($var){
foreach($var as $item){
$return =3D array_merge($return, objects_from_array($item));
}
}
>> }
>> return $return;}
>>
> That function will also enter an endless loop like petesprc
No, it won't like this :P. It will loop through an array and if it's don=
e, =
it will return all objects found. Unless you're doing something very =
strange like putting in a reference to a parent array in a sub array.
> We need to loop inside the array to get the next dimension... don't
> we ? so when you do arraymerge the $var should be the second dimension=
> of the array in the first call of the function.
> my array is like that
> $productArray[$productTypeId][$productId][$published] =3D new
> objectProduct();
>
> so for that i would do 3 nested foreach loops ...
Or just a recursive function.
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|