试图从发布的列表中获取值,但对于所有值我总是得到0

时间:2018-12-06 19:26:13

标签: php loops

<?php

//LOOP

$marigold = 0;

$rose = 0;

$tulip = 0;

for ($y = 0; $i < 5; $y++) { // The loop top limit is 5 because there are 5 objects with ids: 0, 1, 2, 3, 4

    $value = $_POST[$y];

    if ($value == "marigold") $marigold++;

    if ($value == "rose") $rose++;

    if ($value == "tulip") $tulip++;

};

echo "Marigold";

echo "<span id='marigold'> $marigold</span>";

echo "<br>";

echo "Rose";

echo "<span id='rose'> $rose</span>";

echo "<br>";

echo "Tulip";

echo "<span id='tulip'> $tulip</span>";

?>

1 个答案:

答案 0 :(得分:0)

我怀疑您已将ini设置“ display_errors”设置为关闭。因为此行for ($y = 0; $i < 5; $y++)将给出“未定义的变量”错误。没有$i。也许将display_errors设置为on(类似ini_set('display_errors', '1');),或者至少查看php错误日志以查看该程序是否正在报告错误。没有太多反馈。