|
Posted by Rik on 02/07/07 16:25
Aggelos <djjelly@gmail.com> wrote:
> function objects_from_array($var){
> $return =3D array();
> if(is_object($var)){
> $return =3D $var;
> }
> if(is_array($var)){
> foreach($var as $item){
> $return =3D array_merge($return, objects_from_array($item));
>
> }
> }
> return $return;
> }
>
> Ok that will work now but it is not what I want because at the end my
> object gets converted into an assiciative array.
Not in my code, I assume in something you want to do afterwards? I told =
=
you I did not know in which format you want the return.
> So my product->title now would become product[;title']
Euh? That's something entirely different. Please explain your exact =
intentions from start to finish, would make it a lot easier to give you =
an =
answer you can actually use :-)
> Do you know why my version isn't working ? you said something about
> void... but i didn't understood that...
This part:
function recurseArray($array) {
if(is_array($array)) {
foreach($array as $arrayValue) {
recurseArray($arrayValue);
-----------------------^^
If the $array you feed it is an object, the same object is immediately =
returned. So far so good. If it is an array, you perform the function on=
=
each item of the array. This may or may not return an object. However, =
there's nothing 'to the left' of this recurseArray($arrayValue), which =
means that whatever it returns, it is not assigned to anything, so =
whatever it returns is lost. If you feed it an array, the function is =
performed on every item, but isn't 'saved'. The only 'return' there is f=
or =
when it's an object, so if it's not an object your function will return =
=
nothing/null/nada.
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|