mikebarbaro Posted January 28, 2010 Share Posted January 28, 2010 Hello, I have the following code which is needed to display all the values of an array by themselves in a list and include it in a fax. The problem is only the first item in the array prints out. So, if I have the following in an array only Chicken Salad would show up in the fax: Chicken Salad Nachos Root Beer I need all three to show up just as listed above! Any help is appreciated! $items = $_SESSION['items']; foreach ($items as $itemname) { $finalitems = $itemname . '<br />'; // Combine data to be faxed $params->Data = $texttofax . $finalitems; } Link to comment https://forums.phpfreaks.com/topic/190131-issue-with-array-and-foreach-statement/ Share on other sites More sharing options...
soycharliente Posted January 28, 2010 Share Posted January 28, 2010 You're resetting your $params attribute every time? Don't you want to tack on the new stuff to the end? Link to comment https://forums.phpfreaks.com/topic/190131-issue-with-array-and-foreach-statement/#findComment-1003160 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 $items = $_SESSION['items']; foreach ($items as $itemname) { $finalitems = $itemname . '<br />'; // Combine data to be faxed $params->Data = $texttofax . $finalitems; } $items = $_SESSION['items']; foreach ($items as $itemname) { $finalitems = $itemname . '<br />'; } // <-----MOVED / ADDED A BRACKET // Combine data to be faxed <---- DO THIS AFTER BRACKET MAYBE?!?! Else as pointed out you are resetting your data. $params->Data = $texttofax . $finalitems; Link to comment https://forums.phpfreaks.com/topic/190131-issue-with-array-and-foreach-statement/#findComment-1003162 Share on other sites More sharing options...
soycharliente Posted January 28, 2010 Share Posted January 28, 2010 $items = $_SESSION['items']; foreach ($items as $itemname) { $finalitems = $itemname . '<br />'; } // <-----MOVED / ADDED A BRACKET $params->Data = $texttofax . $finalitems; That is still not quite right. You need to concatenate the data inside the loop. $items = $_SESSION['items']; foreach ($items as $itemname) { $finalitems .= $itemname . '<br />'; //changed this line } // Combine data to be faxed $params->Data = $texttofax . $finalitems; Link to comment https://forums.phpfreaks.com/topic/190131-issue-with-array-and-foreach-statement/#findComment-1003165 Share on other sites More sharing options...
mikebarbaro Posted January 28, 2010 Author Share Posted January 28, 2010 $items = $_SESSION['items']; foreach ($items as $itemname) { $finalitems = $itemname . '<br />'; } // <-----MOVED / ADDED A BRACKET $params->Data = $texttofax . $finalitems; That is still not quite right. You need to concatenate the data inside the loop. $items = $_SESSION['items']; foreach ($items as $itemname) { $finalitems .= $itemname . '<br />'; //changed this line } // Combine data to be faxed $params->Data = $texttofax . $finalitems; Worked perfectly! Thank you very much! Link to comment https://forums.phpfreaks.com/topic/190131-issue-with-array-and-foreach-statement/#findComment-1003169 Share on other sites More sharing options...
soycharliente Posted January 28, 2010 Share Posted January 28, 2010 Glad we could help. Make sure you use the "mark solved" feature. Link to comment https://forums.phpfreaks.com/topic/190131-issue-with-array-and-foreach-statement/#findComment-1003170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.