Here i am having one multidimensional array , using this array i have to merge the single array, i have tried in my point of view i have to use three foreach loop and then i have to push on one array,but my concern is if i am using foreach loop means my performance it will reduce,any one update my code with out for each loop or simplfied code
My Array
Array
(
"100" => Array
(
"class 1" => Array
(
"0" => "ABC"
"1" => "CDE"
)
"class 2" => Array
(
"0" => "F"
)
)
"200" => Array
(
"class 3" => Array
(
"0" => "G"
)
)
)
Expected Output
Array
(
"0" => "100"
"1" => "ABC"
"2" => "CDE"
"3" => "F"
"4" => "200"
"5" => "G"
)
I had tried like below
<?php
$array = Array
(
"100" => Array
(
"class 1" => Array
(
"0" => "ABC",
"1" => "CDE"
),
"class 2" => Array
(
"0" => "F"
)
),
"200" => Array
(
"class 3" => Array
(
"0" => "G"
)
)
);
foreach($array as $firstKey => $firstVal){
$mainArray[] = $firstKey;
foreach($firstVal as $secondKey => $secondVal){
foreach($secondVal as $thiredKey => $thiredVal){
$mainArray[] = $thiredVal;
}
}
}
echo "<pre>";
print_r($mainArray);
?>
foreach; refer my answer below.