PHP-printf()打印我的部分代码


PHP - printf() prints part of my code

运行以下(简单)代码时:

<?php
$array = array("Blue", "Green", "Yellow", "Pink", "");
foreach ($array as $arrayElement) {
    printf("<div class = '"colorSubArea %s '" > <p> 1 </p> </div> " , $arrayElement);
}

https://jsfiddle.net/xbkky7jx/3/

我的代码的最后一部分正在打印出来。此外,循环在第一次迭代后没有继续(可能是同样的原因)。我是PHP新手,这让我很困惑。

您的php代码还可以,您看不到输出的原因是HTML,请参阅viewsource模式下的输出。

您的输出是:

<div class = "colorSubArea Blue " > <p> 1 </p> </div> 
<div class = "colorSubArea Green " > <p> 1 </p> </div> 
<div class = "colorSubArea Yellow " > <p> 1 </p> </div> 
<div class = "colorSubArea Pink " > <p> 1 </p> </div> 
<div class = "colorSubArea  " > <p> 1 </p> </div>   

请参阅:https://eval.in/568890

          $array = array("Blue", "Green", "Yellow", "Pink", "");
          foreach($array as $arrayElement){  
            printf("%s " , $arrayElement);
          }