为什么这个非常简单的数组迭代不起作用?

时间:2010-08-18 13:06:03

标签: php

我有以下数组

 Array ( [0] => Please enter address line 1 
          [1] => Please tell us your first name 
          [2] => Please tell us your last name 
          [3] => Please tell us your email 
          [4] => You must tell us one phone number 
          [5] => Please tell us second applicants title 
          [6] => Please tell us second applicants first name 
          [7] => Please tell us second applicants last name )

我循环遍历如下                 foreach($error_hash as $value) { echo "error <li> $value <li/>"; }

令人讨厌的是我一直在拿空行

  • 请输入地址第1行
  • 错误
  • 请告诉我们您的名字
  • 错误
  • 等.......
  • 任何输入都会很棒

    3 个答案:

    答案 0 :(得分:5)

    在'li'标签内嵌入'错误',因此不会产生额外的输出。类似的东西:

    echo "<li> error, $value </li>";
    

    答案 1 :(得分:1)

    观看您的标记

    <li/>
    

    也许这会有所帮助:

    </li>
    

    :)

    答案 2 :(得分:1)

    我已经查过了。这是工作。

    $a[0] = 'Please enter address line 1';
    $a[1] = 'Please tell us your first name';
    foreach ($a as $b) {
        echo $b;
    }