PHP输出为空

时间:2019-05-30 20:48:02

标签: php output

这是我的代码php5.6

$lang = array(
  "HTML" => "60%",
  "CSS" => "80%",
  "JS" => "70%",
  "PHP" => "50%",
);

echo "<ul>";

for ($lang=0; $lang < count($lang) ; $lang++) {
  echo "<li>" . $lang[$lang] . "</li>";
}

echo "</ul>";

当我运行我的页面时,它什么也没显示

1 个答案:

答案 0 :(得分:0)

在数组上使用foreach。

$langs = array(
  'HTML'=> '60%',
  'CSS' => '80%',
  'JS'  => '70%',
  'PHP' => '50%',
);

echo '<ul>';

foreach ($langs as $lang=>$per) {
  echo "<li>$lang $per</li>";
}

echo '</ul>';