3 Ways to Flatten a Multidimensional Array Using PHP

Written by Ubaidullah| PHP

Are you facing trouble in flattening a multidimensional/nested array using PHP? In this guide, we are going to discuss the 3 ways to flatten a multidimensional array. Let’s get started:

Table of Contents: Flatten a Multidimensional Array

  1. Using Standard PHP Library
  2. Using array_walk_recursive
  3. Using Stack

Using Standard PHP Library

Example:

Output:

Using array_walk_recursive

Example:

Output:

Using Stack

3 Ways to Flatten a Multidimensional Array Using PHP
Rate this post

Last modified: June 3, 2017

Leave a Reply

Your email address will not be published. Required fields are marked *