Search code examples
phperror-handlingnotice

PHP loop throwing notice, which seems to be a constant error


$features[] = array("Feature 1", "Feature 2", "Feature 3", "Feature 4")

for ($i=0; $i <4 ; $i++) {
echo '<li class="list-group-item text-centre">'.  $features[i] . '</li>';

I am unable to resolve the notice:

Notice: Use of undefined constant i - assumed 'i' in /home3/..../public_html/html......com/all/stripe/index.php on line 48

Solution

  • It cause of $features[]. Use:

    $features = array("Feature 1", "Feature 2", "Feature 3", "Feature 4")
    

    $features[] means that you're passing a value after = into a new index of $features array, i.e. $features[0][your_array]

    And

    echo '<li class="list-group-item text-centre">'. $features[$i] . '</li>';

    replace it with

    echo '<li class="list-group-item text-centre">'.  $features[$i] . '</li>';