problem returning array from function

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
mkultra
Forum Newbie
Posts: 2
Joined: Sat Sep 04, 2010 9:45 am

problem returning array from function

Post by mkultra »

Hey folks, captain Brandnew McNewbie here im having trouble returning an array from a function. The array data will display correctly inside the fucntion but somehow gets lost when i try to assign the return to a variable and display from outside the function. Any comments are greatly appreciated.

//Function snippet
$quote = explode(",",trim($quote_value));

$symbol = str_replace("\"","",$quote[10]);
$value = $quote[0];
$change = $quote[1];
$cap = $quote[2];
$PE = $quote[3];
$PS = $quote[4];
$PBV = $quote[5];
$shares = $quote[6];
$EPS = $quote[7];
$div = $quote[8];
$bookval = $quote[9];
echo "<td>$symbol</td> <td>$value</td> <td>$change</td> <td>$cap</td> <td>$PE</td> <td>$PS</td> <td>$PBV</td> <td>$shares</td> <td>$EPS</td> <td>$div</td> <td>$bookval</td>";
echo "</tr>";
}
echo "</table>";
}
return $quote;
?>




//Calling snippet

$vbuffer=show_stock_quotes($field1);
print " ".$vbuffer." with index ".$vbuffer[0]."<br>";
print"$vbuffer[0]<br>";


neither of the print statements will show anythign but blanks while the function will show the data.
mkultra
Forum Newbie
Posts: 2
Joined: Sat Sep 04, 2010 9:45 am

Re: problem returning array from function

Post by mkultra »

found my own problem :) being that the return statement was in an include file, it was placed after the last brace of the function, thus not getting executed. Sorry for the newb post.
Post Reply