3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 ) );
based on LVrLe
Output for 4.3.0 - 7.2.0
array(5) { ["Users_Name"]=> string(4) "Name" ["Address"]=> string(7) "Address" ["Tags_0_Key"]=> string(3) "Key" ["Tags_0_Value"]=> string(5) "Value" ["Tags_1_Key"]=> string(3) "Key" }