3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function flatten_array($array, $flat = array()) { foreach($array as $k=>$v){ if(!is_array($v)){ while(true){ $i = isset($i) ? $i+1 : 0; $key = "$k$i"; if(!array_key_exists($key, $flat)) break; } $flat[$key] = $v; unset($array[$k]); }else{ $flat = flatten_array($v, $flat); } } return $flat; } $a = array_fill(0, 10, array_fill(0, 10, 0)); $array = flatten_array($a); var_dump($array);
based on mSPE8
Output for 4.3.0 - 7.2.0
array(100) { ["00"]=> int(0) [11]=> int(0) [22]=> int(0) [33]=> int(0) [44]=> int(0) [55]=> int(0) [66]=> int(0) [77]=> int(0) [88]=> int(0) [99]=> int(0) ["01"]=> int(0) [12]=> int(0) [23]=> int(0) [34]=> int(0) [45]=> int(0) [56]=> int(0) [67]=> int(0) [78]=> int(0) [89]=> int(0) [910]=> int(0) ["02"]=> int(0) [13]=> int(0) [24]=> int(0) [35]=> int(0) [46]=> int(0) [57]=> int(0) [68]=> int(0) [79]=> int(0) [810]=> int(0) [911]=> int(0) ["03"]=> int(0) [14]=> int(0) [25]=> int(0) [36]=> int(0) [47]=> int(0) [58]=> int(0) [69]=> int(0) [710]=> int(0) [811]=> int(0) [912]=> int(0) ["04"]=> int(0) [15]=> int(0) [26]=> int(0) [37]=> int(0) [48]=> int(0) [59]=> int(0) [610]=> int(0) [711]=> int(0) [812]=> int(0) [913]=> int(0) ["05"]=> int(0) [16]=> int(0) [27]=> int(0) [38]=> int(0) [49]=> int(0) [510]=> int(0) [611]=> int(0) [712]=> int(0) [813]=> int(0) [914]=> int(0) ["06"]=> int(0) [17]=> int(0) [28]=> int(0) [39]=> int(0) [410]=> int(0) [511]=> int(0) [612]=> int(0) [713]=> int(0) [814]=> int(0) [915]=> int(0) ["07"]=> int(0) [18]=> int(0) [29]=> int(0) [310]=> int(0) [411]=> int(0) [512]=> int(0) [613]=> int(0) [714]=> int(0) [815]=> int(0) [916]=> int(0) ["08"]=> int(0) [19]=> int(0) [210]=> int(0) [311]=> int(0) [412]=> int(0) [513]=> int(0) [614]=> int(0) [715]=> int(0) [816]=> int(0) [917]=> int(0) ["09"]=> int(0) [110]=> int(0) [211]=> int(0) [312]=> int(0) [413]=> int(0) [514]=> int(0) [615]=> int(0) [716]=> int(0) [817]=> int(0) [918]=> int(0) }