Category: PHP

Iterating over a nested menu isn’t that easy, especially when we got a big menu with many nested levels. The problem that I want to solve here is to build an unordered HTML list that is based on a multi-level nested menu for our products: I will be using the SPL library to solve this problem. SPL provides a bunch of iterators, In this post I will be using both RecursiveArrayIterator as well as RecursiveIteratorIterator. As its name implies, the RecursiveArrayIterator iterates over a given array, but it doesn’t support nested arrays, therefore we also need to use the RecursiveIteratorIterator. Let’s get started: The RecursiveIteratorIterator class has four methods that will react when a particular event occurs, these methods are: beginIteration, endIteration, beginChildren and endChildren.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners