Jump to content

Very Simple, Trying To Use A Variable As An Input In An Array Parameter


phpchick

Recommended Posts

I have this super simple function

 

 

  function getstockstats($stocksymbol)
 {
include_once('ii-prediction-log-widget/class.yahoostock.php');
$objYahooStock = new YahooStock;
$objYahooStock->addFormat("snl1d1t1cvc1p2");
$objYahooStock->addStock("$stocksymbol");

foreach( $objYahooStock->getQuotes() as $code => $stock)
{
echo $stock[0];
}

 }

 

when I use the function, I pass it a symbol like this

 

getstockstats("aapl");

 

I want this line

$objYahooStock->addStock("$stocksymbol");

to receive the variable (aapl), instead, its reading it as $stocksymbol

 

I know there is a way to exit that but I can't for the life of me figure it out because it is so hard to explain that portion. Can someone help me?

 

I've tried wrapping it in {}

 

like this

 

$objYahooStock->addStock("{$stocksymbol}");

 

but that did not work either. Thank you!! <3

Have you tried removing the double-quotes?

 

Instead:

 

$objYahooStock->addStock($stocksymbol);

 

Not sure that will make a difference. Doesn't with procedural functions. Methods might be different (somebody else chime in here).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.