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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners