Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在foreach中只回显一次代码_Php_Foreach - Fatal编程技术网

Php 如何在foreach中只回显一次代码

Php 如何在foreach中只回显一次代码,php,foreach,Php,Foreach,我试图在foreach中只回显一次变量 这是变量:$ads 代码如下: foreach ( $chapter['storage'][ $in_use ]['page'] as $page => $link ) { $host = $chapter['storage'][ $in_use ]['host']; $src = $host . $link['src']; ?> <div class="

我试图在foreach中只回显一次变量 这是变量:$ads

代码如下:

    foreach ( $chapter['storage'][ $in_use ]['page'] as $page => $link ) {
        $host = $chapter['storage'][ $in_use ]['host'];
        $src  = $host . $link['src'];
        ?>
        <div class="page-break">
            <img id="image-<?php echo esc_attr( $page ); ?>" src="<?php echo esc_url( $src ); ?>" class ="wp-manga-chapter-img">
        </div>
    }
 
foreach($page=>chapter['storage'][$in_use]['page']as$page=>$link){
$host=$chapter['storage'][$in_use]['host'];
$src=$host.$link['src'];
?>
“class=“wp漫画章节img”>
}

您可以简单地使用如下计数器:

$i = 0;
foreach ( $chapter['storage'][ $in_use ]['page'] as $page => $link ) {
    if($i==0) echo($ads);
    $i++;
    $host = $chapter['storage'][ $in_use ]['host'];
    $src  = $host . $link['src'];
    ?>
    <div class="page-break">
        <img id="image-<?php echo esc_attr( $page ); ?>" src="<?php echo esc_url( $src ); ?>" class ="wp-manga-chapter-img">
    </div>
$i=0;
foreach($page=>$link的章['storage'][$in_use]['page']as$page){
如果($i==0)回波($ads);
$i++;
$host=$chapter['storage'][$in_use]['host'];
$src=$host.$link['src'];
?>
“class=“wp漫画章节img”>

您可以简单地使用如下计数器:

$i = 0;
foreach ( $chapter['storage'][ $in_use ]['page'] as $page => $link ) {
    if($i==0) echo($ads);
    $i++;
    $host = $chapter['storage'][ $in_use ]['host'];
    $src  = $host . $link['src'];
    ?>
    <div class="page-break">
        <img id="image-<?php echo esc_attr( $page ); ?>" src="<?php echo esc_url( $src ); ?>" class ="wp-manga-chapter-img">
    </div>
$i=0;
foreach($page=>$link的章['storage'][$in_use]['page']as$page){
如果($i==0)回波($ads);
$i++;
$host=$chapter['storage'][$in_use]['host'];
$src=$host.$link['src'];
?>
“class=“wp漫画章节img”>
在循环之前回显它不是更容易(除非
$ads
依赖于循环中的数据)吗?在循环之前回显它不是更容易(除非
$ads
依赖于循环中的数据)吗?