Skip to content

Instantly share code, notes, and snippets.

@Asikur22
Last active October 1, 2024 21:05
Show Gist options
  • Save Asikur22/407925df30c8c7f46194df8b9b987e4c to your computer and use it in GitHub Desktop.
Save Asikur22/407925df30c8c7f46194df8b9b987e4c to your computer and use it in GitHub Desktop.
Convert a multi-dimentional array to a single dimension array. #array_flatten
/*
* 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