How to loop through this array in PHP?

Spread the love

Sometimes, we want to loop through this array in PHP.

In this article, we’ll look at how to loop through this array in PHP.

How to loop through this array in PHP?

To loop through this array in PHP, we can use a foreach loop.

For instance, we write

foreach ($array as $item) {
    echo $item["filename"];
    echo $item["filepath"];
    echo "<pre>";
    var_dump($item);
}

to loop through the $array and get the item being looped through from $item.

Then we get the values from the $item associative array in the loop body.

Conclusion

To loop through this array in PHP, we can use a foreach loop.

Leave a Reply

Your email address will not be published.