3v4l.org

run code in 300+ PHP versions simultaneously
<?php function transfer( $arr, $prefix=array(), $glue="_" ) { $res = array(); foreach( $arr as $key => $val ) { $key = array_merge( $prefix, array($key) ); if( is_array($val) ) $res = array_merge( $res, transfer( $val, $key, $glue ) ); else $res[ implode($glue, $key) ] = $val; } return $res; } $attributes = array( 'Users' => array( 'Name' => 'Name', ), 'Address' => 'Address', 'Tags' => array( 0 => array( 'Key' => 'Key', 'Value' => 'Value', ), 1 => array( 'Key' => 'Key', ), 2 => array( ) ), ); var_dump( transfer( $attributes ) );

preferences:
52.93 ms | 402 KiB | 5 Q