PHP-将每个变量传递给新的foreach
如何将每个变量传递给新的foreach 我有这个:PHP-将每个变量传递给新的foreach,php,simple-html-dom,Php,Simple Html Dom,如何将每个变量传递给新的foreach 我有这个: <?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>
<?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>";
?>
所需:所有链接作为新foreach函数的变量
<?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;
?>
任何帮助都将不胜感激我想你说的是一个数组
$links = array();
$html = file_get_html('http://www.homepage.com/');
foreach($html->find('figure a') as $eventLink)
$links[] = $urlVariable.$eventLink->href;
您将每个值添加到数组中的一个位置,而不是重复
要将数组添加到foreach函数,只需执行以下操作
foreach($item in $links)
echo $item
我希望有一个包含所有抓取链接的变量,然后将此变量用于新的foreach函数。第一个回音只是为了测试。那么,只需将数组添加到foreach函数中,您能否在回答中添加一个示例,如何将数组添加到foreach函数中?那太好了!Thx,但它会导致崩溃。当我调用“var_dump($links);”时,它会显示数组。我会将此数组作为变量传递,以便从url数组-“$links”)中查找每个站点中的“.text”内容,然后进行回显。(请看一看我上面的问题,->需要)好的,拿一个打印屏幕粘贴到imgur上,文本有点难读
foreach($item in $links)
echo $item