Jump to content

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

Why are you executing split() against $symbol_list when it's already an array

 

either

$symbol_list = "MCD,^DJI";

 

or

 

comment out

// $sym_list = split(", ", $symbol);

and change

foreach ($sym_list as $value)

to

foreach ($symbol as $value)

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.