我有一个包含n个数组的数组。数组的结构如下:
bigarray(
[array1]=a,b,c,d;
[array2]=[a,c,e]
[array3]=[d,e,f]
)
我想存储来自" child"的所有值。一个数组中的数组。
那样:$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);
?>