Page 1 of 1

inject object array

Posted: Wed Dec 15, 2004 6:46 pm
by ol4pr0
Oke

i get an array back from a class [ query from db ]
the returned array looks kinda like this

Array ( [0] => stdClass Object ( [id] => 1 [name] => birdy [link] => birdy ect..

That array i am injecting into another class again.

than the function in that class:

Code: Select all

function _downloads( &$myarray ) {
	foreach ($myarray as $retarray) {
        $ret = $retarray->name;
        }
        return $ret;
}
This will return a value but only the last or the first value of the array. It should be all of them.

if i would skip the whole foreach thing. and return $myarray it will return a object array again. the same as it got injected into the function.

Array ( [0] => stdClass Object ( [id] => 1 [name] => birdy [link] => birdy ect..

So what am i missing here !?

Posted: Wed Dec 15, 2004 7:01 pm
by andre_c
try adding the square brackets at the end of the $ret array:

Code: Select all

<?
function _downloads( &$myarray ) {
    foreach ($myarray as $retarray) {
        $ret[] = $retarray->name;
        }
        return $ret;
}
?>

Posted: Wed Dec 15, 2004 7:21 pm
by ol4pr0
Speaking about birdy ( sig ) lol...

Thanks andre_c ( that got me a whole lot further :) )