leke Posted April 9, 2010 Share Posted April 9, 2010 Hi, The foreach loop below looks like it is assigning some key => value pairs to some html output. Is there a way I can assign the output to an array so I can access it by key outside the loop? Thanks...code follows... <?php include 'simple_html_dom.php'; // source: http://www.bitrepository.com/php-simple-html-dom-parser.html $url = 'http://www.amica.fi/Ravintolat/Amica-ravintolat/Ravintolat-kaupungeittain/Tampere/Technopolis-Hermia--Hermia'; $html = file_get_html($url); foreach($html->find('div[class=ContentArea]') as $key => $info) { echo $key.$info."<br><br>\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/198117-output-to-an-array/ Share on other sites More sharing options...
monkeytooth Posted April 9, 2010 Share Posted April 9, 2010 if you need the html output keep it the way it is, to store it for later usage while the script is still running try adding $myArray = array(); just above the foreach statement under $html then in the foreach loop $myArray[] = $info; if you need the array your making at a later time, on another page or else where I might suggest storing it as a session which you would just add $_SESSION['myArray'] = $myArray; after the foreach loop This is just concept I havent tested this theroy. It should work but may require a little play to get it right you can also look into array_push(), or atleast i think thats the name of it. Link to comment https://forums.phpfreaks.com/topic/198117-output-to-an-array/#findComment-1039477 Share on other sites More sharing options...
leke Posted April 9, 2010 Author Share Posted April 9, 2010 Thanks, That worked perfectly Link to comment https://forums.phpfreaks.com/topic/198117-output-to-an-array/#findComment-1039493 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.