3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function flatten_array($array, $flat = array()) { foreach($array as $k=>$v){ $k = strval($k); if(!is_array($v)){ $i = 0; while(true){ $i++; $key = $k.strval($i); if(!isset($flat[$key])) 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 qTDm3
Output for 4.3.0 - 7.2.0
array(100) { ["01"]=> int(0) [11]=> int(0) [21]=> int(0) [31]=> int(0) [41]=> int(0) [51]=> int(0) [61]=> int(0) [71]=> int(0) [81]=> int(0) [91]=> int(0) ["02"]=> int(0) [12]=> int(0) [22]=> int(0) [32]=> int(0) [42]=> int(0) [52]=> int(0) [62]=> int(0) [72]=> int(0) [82]=> int(0) [92]=> int(0) ["03"]=> int(0) [13]=> int(0) [23]=> int(0) [33]=> int(0) [43]=> int(0) [53]=> int(0) [63]=> int(0) [73]=> int(0) [83]=> int(0) [93]=> int(0) ["04"]=> int(0) [14]=> int(0) [24]=> int(0) [34]=> int(0) [44]=> int(0) [54]=> int(0) [64]=> int(0) [74]=> int(0) [84]=> int(0) [94]=> int(0) ["05"]=> int(0) [15]=> int(0) [25]=> int(0) [35]=> int(0) [45]=> int(0) [55]=> int(0) [65]=> int(0) [75]=> int(0) [85]=> int(0) [95]=> int(0) ["06"]=> int(0) [16]=> int(0) [26]=> int(0) [36]=> int(0) [46]=> int(0) [56]=> int(0) [66]=> int(0) [76]=> int(0) [86]=> int(0) [96]=> int(0) ["07"]=> int(0) [17]=> int(0) [27]=> int(0) [37]=> int(0) [47]=> int(0) [57]=> int(0) [67]=> int(0) [77]=> int(0) [87]=> int(0) [97]=> int(0) ["08"]=> int(0) [18]=> int(0) [28]=> int(0) [38]=> int(0) [48]=> int(0) [58]=> int(0) [68]=> int(0) [78]=> int(0) [88]=> int(0) [98]=> int(0) ["09"]=> int(0) [19]=> int(0) [29]=> int(0) [39]=> int(0) [49]=> int(0) [59]=> int(0) [69]=> int(0) [79]=> int(0) [89]=> int(0) [99]=> int(0) ["010"]=> int(0) [110]=> int(0) [210]=> int(0) [310]=> int(0) [410]=> int(0) [510]=> int(0) [610]=> int(0) [710]=> int(0) [810]=> int(0) [910]=> int(0) }