phpchick Posted November 23, 2012 Share Posted November 23, 2012 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 Link to comment https://forums.phpfreaks.com/topic/271086-very-simple-trying-to-use-a-variable-as-an-input-in-an-array-parameter/ Share on other sites More sharing options...
mrMarcus Posted November 23, 2012 Share Posted November 23, 2012 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). Link to comment https://forums.phpfreaks.com/topic/271086-very-simple-trying-to-use-a-variable-as-an-input-in-an-array-parameter/#findComment-1394675 Share on other sites More sharing options...
phpchick Posted November 23, 2012 Author Share Posted November 23, 2012 Yes that worked! That was actually the first thing I tried and it didn't work (then) but now it works. so yay I must have had a typo in there when I did it the first time. Thanks Mr Marcus. Link to comment https://forums.phpfreaks.com/topic/271086-very-simple-trying-to-use-a-variable-as-an-input-in-an-array-parameter/#findComment-1394678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.