Last active
October 1, 2024 21:05
-
-
Save Asikur22/407925df30c8c7f46194df8b9b987e4c to your computer and use it in GitHub Desktop.
Convert a multi-dimentional array to a single dimension array. #array_flatten
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Convert a multi-dimentional array to a single dimension array. | |
*/ | |
public static function array_flatten( array $arr ) { | |
$flattened = array(); | |
foreach ( $arr as $key => $value ) { | |
if ( is_array( $value ) ) { | |
$flattened = array_merge( $flattened, self::array_flatten( $value ) ); | |
} else { | |
$flattened[ $key ] = $value; | |
} | |
} | |
return $flattened; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment