I am trying to extract some info from a website using simple_html_dom.
Currently I am using:
foreach ($html->find('div.product') as $results) {
foreach ($results->find('div.image') as $img) {
echo $img;
}
foreach ($results->find('a.title') as $title) {
echo $title->plaintext;
}
foreach ($results->find('div.price') as $price) {
echo $price;
}
}
Which works fine. However I need to be able to echo each variable outside of the foreach loop. If I do that using the above code, only the final result will be displayed, i.e. out of the 10 products I am trying to extract only the 10th will be displayed.
Is there a way I can use an array to store all the results from each foreach loop then echo them out once the overall loop is finished?
Something like this:
foreach ($html->find('div.product') as $results) {
foreach ($results->find('div.image') as $img) {
array($img);
}
foreach ($results->find('a.title') as $title) {
array($title->plaintext);
}
foreach ($results->find('div.price') as $price) {
array($price);
}
}
echo array($img);
echo array($title);
echo array($price);
Sorry if this question is confusing I don't have the best grasp on PHP, especially arrays!
$results->findalready returns arrays, right?