Skip to content

Instantly share code, notes, and snippets.

@kjohnson
Created September 22, 2015 19:12
Show Gist options
  • Select an option

  • Save kjohnson/fe4c90b482364e5062c9 to your computer and use it in GitHub Desktop.

Select an option

Save kjohnson/fe4c90b482364e5062c9 to your computer and use it in GitHub Desktop.
Multi Dimensional Array to Single Deminsional Array
<?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