<?php
$samples = [
123,
[1, 2, 3],
321
];
$samples_modified = [];
array_walk_recursive($samples, function ($item, $key) use (&$samples_modified) {
$samples_modified[] = $item;
});
print_r($samples_modified);
UPD:
Вариант с
foreach:
<?php
$samples = [
123,
[1, 2, 3],
321
];
$samples_modified = [];
function recursive_func($array){
global $samples_modified;
if(is_array($array)){
foreach($array as $below){
$res = recursive_func($below);
}
}else{
$samples_modified[] = $array;
}
return $samples_modified;
}
recursive_func($samples);
print_r($samples_modified);
P.S.: За
global помидорами не кидайте...чисто для примера...