Jump to content

[SOLVED] foreach();


denoteone

Recommended Posts

I think I have an issue with my array but and not sure. can anyone see what I am doing wrong?

 

$symbol_list = array("MCD", "^DJI");

$feed = GetQuote($symbol_list);

$sym_list = split(", ", $symbol);
foreach ($sym_list as $value)
{
echo $value;
}

Am I using this is the correct way?

Link to comment
https://forums.phpfreaks.com/topic/150181-solved-foreach/
Share on other sites

here is the code in full. the symbol  is the symbol is the symbol_list array.

 


$symbol_list = array("MCD", "^DJI");
$feed = GetQuote($symbol_list);

echo $feed;

$fp = fopen("drop.xml", "a");
fwrite($fp, $feed);

function GetQuote($symbol)  
{

// Build xml result as we go
$xml_result = "<StockQuotes>";

// create symbol list
$sym_list = split(", ", $symbol);
foreach ($sym_list as $value)
{
               echo $value;        
}

Link to comment
https://forums.phpfreaks.com/topic/150181-solved-foreach/#findComment-788689
Share on other sites

Try:

 

$symbol_list = array("MCD", "^DJI");
$feed = GetQuote($symbol_list);

echo $feed;

$fp = fopen("drop.xml", "a");
fwrite($fp, $feed);
fclose($fp);

function GetQuote($symbol) 
{

   // Build xml result as we go
   $xml_result = "\n";
   
   // Grab each stock symbol and concatenate it to $xml_result 
   foreach ($symbol as $value)
   {
      $xml_result .= $value . "\n";
   }
   
   $xml_result .= "";
   return $xml_result;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/150181-solved-foreach/#findComment-788701
Share on other sites

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.