如何将n个数组的值存储在一个数组中



我有一个包含n个数组的数组,数组的结构是这样的:

bigarray(
[array1]=a,b,c,d;
[array2]=[a,c,e]
[array3]=[d,e,f]
)

我想把"子"数组中的所有值存储在一个数组中。$array=a,b,c,d,a,c,e,d,e,f......

<?php
/*Here is the Demonstration for your case in PHP .*/
$array_1 = array("alpha","beta","gamma"); // Array 1
$array_2 = array("hey","hi","hello"); // Array 2
$array_3 = array("apple","ball","cat"); // Array3
$big_array = array($array_1,$array_2,$array_3); // Main Array which is combination of array 1 ,2 and 3
$final_output = array();
$inbetween_output = "";   // Temporay variable
$lastElement = end($big_array); // Check if last element of array
foreach($big_array as $key=>$value){
    $combine = implode(',', $value);   // Implode array values for array 1 , 2 and 3
    $inbetween_output .= $combine;  // storing imploded values in temporary variable
    if($value != $lastElement){ // If last element of array then dont add semi-colon at the end
        $inbetween_output .= ",";
    }
}
$final_output[] = $inbetween_output; // move your data from temporary variable to output array
unset($inbetween_output);  // Release memory occupied by temporary variable
print_r($final_output); 
?> 

相关内容

  • 没有找到相关文章

最新更新