inject object array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

inject object array

Post 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 !?
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post 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;
}
?>
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Speaking about birdy ( sig ) lol...

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