k3vy w3vy
k3vy w3vy

Reputation: 131

iterate through php array and create a span

I have an array of items that I'm trying to traverse through to place on the screen. I can traverse the array just fine but I'm also trying to use span to display the item. I'm not sure how to do this. Any help would be greatly appreciated.

        foreach($itemsArray as $item)
        {
            '<span class="item '.$team.'">'.img('it', $item).'</span>'
        }

I can display the items by just calling the item name, but I would really like to traverse an array of items as the way that it is displayed on the website isn't the way that I would like if I call them separately.

This is how I was doing it before.

<span class="item '.$team.'">'.img('it', $item0).'</span>

Upvotes: 0

Views: 388

Answers (2)

k3vy w3vy
k3vy w3vy

Reputation: 131

I was able to figure out the issue. The issue wasn't with that piece of code.

    $itemsArray = array();
    $itemsArray[$i] = $item0;

I was using $array = $item0;

Upvotes: 0

user4628565
user4628565

Reputation:

try to use a for loop,if you get confused,

for($i=0;$i<sizeof($itemsArray);$i++)
    {
        '<span class="item '.$team.'">'.img('it', $itemsArray[$i]).'</span>'
    }

Upvotes: 1

Related Questions