2014-06-05 95 views
-1

我已經1個陣列包含n個陣列排列的.The結構是這樣的:如何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......

我怎麼能這樣做?

+0

你說什麼語言? –

回答

0
<?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); 
?>