PHP:从另一个脚本回显herdoc

PHP:从另一个脚本回显herdoc,php,while-loop,echo,heredoc,Php,While Loop,Echo,Heredoc,我很难将herdeoc语句从一个php文件回显到另一个php文件中。我有一个脚本,用于检索API数据库信息,然后将该信息格式化为herdoc,以将信息回显到index.php页面。我拥有的代码是: while($artist_info = $artist_details_resource->fetch_assoc()){ $artist = <<<DOC <img src="{$artist_info['image_url']}" a

我很难将
herdeoc
语句从一个php文件回显到另一个php文件中。我有一个脚本,用于检索API数据库信息,然后将该信息格式化为
herdoc
,以将信息回显到
index.php
页面。我拥有的代码是:

while($artist_info = $artist_details_resource->fetch_assoc()){
   $artist = <<<DOC
             <img src="{$artist_info['image_url']}" alt="$artist_info['artist_name']" />
             <p>{$artist_name}</p>
DOC;
}
while($artist\u info=$artist\u details\u resource->fetch\u assoc()){

$artist=为什么会这样?你没有在循环中回显它,也没有连接字符串。你在每次迭代中都会覆盖字符串

while($artist_info = $artist_details_resource->fetch_assoc()){
   $artist .= <<<DOC
             <img src="{$artist_info['image_url']}" alt="$artist_info['artist_name']" />
             <p>{$artist_name}</p>
}
while($artist\u info=$artist\u details\u resource->fetch\u assoc()){

$artist.=当然,这只打印最后一个字符串,因为您使用了
$artist=是否尝试从同一个脚本打印它?是的,即使在同一个脚本上,它也只打印最后一个元素这不是herodoc缺少结束文档吗顺便说一句,结束文档在代码块之外
while($artist_info = $artist_details_resource->fetch_assoc()){
   $artist .= <<<DOC
             <img src="{$artist_info['image_url']}" alt="$artist_info['artist_name']" />
             <p>{$artist_name}</p>
}