How to pass each variable variable to new foreach
I have this:
<?php
include_once('js/simple_html_dom.php');
$html = file_get_html('http://www.homepage.com/');
foreach($html->find('figure a') as $eventLink)
echo $urlVariable.$eventLink->href . "<br>";
?>
This works, result:
http://www.homepage.com/link1
http://www.homepage.com/link2
http://www.homepage.com/link3
http://www.homepage.com/link4
...
Desired: all the links as variable for a new foreach-function
<?php
include_once('js/simple_html_dom.php');
$html = file_get_html('http://www.homepage.com/');
foreach($html->find('figure a') as $eventLink)
echo $urlVariable.$eventLink->href . "<br>";
// Desired:
$newGrabbedLinks = .... // (should be ALL grabbed links equal to: echo $urlVariable.$eventLink->href )
foreach($newGrabbedLinks->find('.text') as $newTexts)
echo $newTexts->innertext;
?>
Any help would be appreciated
Well I think what you're talking about is an array.
$links = array();
$html = file_get_html('http://www.homepage.com/');
foreach($html->find('figure a') as $eventLink)
$links[] = $urlVariable.$eventLink->href;
Instead of echoing you're adding each value to a position in your array.
To add the array to a foreach function you would simply do
foreach($item in $links)
echo $item