0

i'm trying to iterate through an array as follows:

$data = array(
    "i0" => "item 0",
    "i1" => "item 1",
    "i2" => "item 2",
    "i3" => "item 3",
    "i4" => "item 4",
    "i5" => "item 5"
);


foreach($data as $id=>$capt);
{
    echo $id.": ".$capt."<br>";
}

i'm expecting getting 6 elements, but the foreach loop will only output the last item. any ideas why? thanks

1 Answer 1

2

The error is in foreach($data as $id=>$capt);, it should not have a ; at the end. Remove it and the loop will work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.