Flatten Nested Arrays Using PHP

In this post I would like to share with you code snippet, which you can use to flatten nested array into one array with string keys with dot notation. This function takes nested array as input.

While working with laravel framework, I found array_flatten() method, this method will also flatten a multi-dimensional array into a single level array but only difference is , it does not support string indexes, it will return final array with numeric indexes.

The following is what I came up to flatten array with same keys and depth with dot notation. see the below example output for better understanding.

How to use

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.
DMCA.com Protection Status