<?php
$animals = array('pig', 'chicken', 'cow', 'snake');
$i = 0;
while ($i < 10)
{
echo "<li>$animals[$i]</li>";
}
?>
I just wanna see the pig, chicken, cow and snake in list item.. but what happen is it just looping the word pig infinitely...
$i++;is missing, and you should modify your loop statement towhile ($i < count($animals)) { ... }. Thecount($animals)statement was also in Ankur's answer, but there wasn't any explanation to that or$i++;.$i++adds one to$iso that$idoesn't forever stay at0. Also, to prevent out-of-bounds undefined behavior evils, I usedcount($animals). Don't go undefined. Don't do it.