Created
September 22, 2015 19:12
-
-
Save kjohnson/fe4c90b482364e5062c9 to your computer and use it in GitHub Desktop.
Multi Dimensional Array to Single Deminsional Array
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
| <?php | |
| function multi_to_single_r( $array ){ | |
| foreach( $array as $key => $value ){ | |
| if( is_array( $value ) ){ | |
| unset( $array[ $key ] ); | |
| $value = multi_to_single_r( $value ); | |
| $array = array_merge( $array, $value ); | |
| } | |
| } | |
| return $array; | |
| } | |
| $array = array( | |
| 'aye', | |
| array( | |
| 'bee', | |
| array( | |
| 'sea' | |
| ) | |
| ) | |
| ); | |
| $array = multi_to_single_r( $array ); | |
| echo "<pre>"; | |
| var_dump( $array ); | |
| echo "</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment