Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.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 使用变量concatenization在循环中回显某些内容_Php_If Statement_Foreach - Fatal编程技术网

Php 使用变量concatenization在循环中回显某些内容

Php 使用变量concatenization在循环中回显某些内容,php,if-statement,foreach,Php,If Statement,Foreach,当如果($I++==0)时,如何在$HERE位置回显活动的 $i=0; foreach($img形式的图像){ $carousel.=' ... '; } 在此处初始化变量$,如下所示: $i = 0; foreach ( $images as $img) { if($i++ == 0){ $HERE = "active"; } else{ $HERE = ""; } $carousel .= ' <d

如果($I++==0)
时,如何在
$HERE
位置回显
活动的

$i=0;
foreach($img形式的图像){
$carousel.='
...
';
}

在此处初始化变量
$
,如下所示:

  $i = 0;
  foreach ( $images as $img) {
    if($i++ == 0){
        $HERE = "active";
    }
    else{
        $HERE = "";
    }
    $carousel .= '
    <div class="item '.$HERE.'">
      ...
    </div>
    ';

  }
$i=0;
foreach($img形式的图像){
如果($i++==0){
$HERE=“active”;
}
否则{
$HERE=“”;
}
$carousel.='
...
';
}
您也可以使用此选项

<?php
$i = 0;
  foreach ( $images as $img) {
 $HERE = ($i++ == 0 ? 'active':'');
    $carousel .= '
    <div class="item '.$HERE.'">
      ...
    </div>
    ';

  }

此处的
$HERE
从何处来或从何处计算?请尝试以下操作:->>>$carousel.='…';
<?php
$i = 0;
  foreach ( $images as $img) {
 $HERE = ($i++ == 0 ? 'active':'');
    $carousel .= '
    <div class="item '.$HERE.'">
      ...
    </div>
    ';

  }