hinchcliffe Posted February 4, 2010 Share Posted February 4, 2010 Hello, Is there a way I can echo an for each variable outside the for each statement? <?php foreach ($products as &$value) { $partnumber = '<PartNumber>'.$value["sku"].'</PartNumber>'; echo $partnumber; } ?> I need $partnumber to be echoed in another piece of php code with out using the for each to grab each value. How can this be done? *EDIT* - Crap I posted in the wrong forum, still if you can help this would be nice. Quote Link to comment https://forums.phpfreaks.com/topic/190858-foreach-values-into-a-variable-need-help/ Share on other sites More sharing options...
khr2003 Posted February 4, 2010 Share Posted February 4, 2010 hi you can add an array that grabs the values of the foreach loop and then read it somewhere else, like this: <?php foreach ($products as &$value) { $partnumber = '<PartNumber>'.$value["sku"].'</PartNumber>'; $array[$value] .= $value; } // then outside the loop echo $array[The value of the array to be printed]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/190858-foreach-values-into-a-variable-need-help/#findComment-1006499 Share on other sites More sharing options...
hinchcliffe Posted February 8, 2010 Author Share Posted February 8, 2010 Thank you, this worked like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/190858-foreach-values-into-a-variable-need-help/#findComment-1009005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.