<?php
function arrayFlat($arr){
$out = '';
foreach($arr as $key => $value){
if(!is_array($value)){
$out .= $value.',';
}else{
$out .= $key.',';
$out .= arrayFlat($value);
}
}
return trim($out,',');
}
$aNonFlat = array(
1,
2,
array(
3,
4,
5,
array(
6,
7
),
8,
9,
),
10,
11
);
$result = explode(',',arrayFlat($aNonFlat));
echo '<pre>';
print_r($result);
echo '</pre>';
- Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- <pre>Array
(
[0] => 1
[1] => 2
[2] => 2
[3] => 3
[4] => 4
[5] => 5
[6] => 3
[7] => 6
[8] => 78
[9] => 910
[10] => 11
)
</pre>
preferences:
136.79 ms | 408 KiB | 5 Q