我有3个阵列:
$array1 = array (1 => 'Hello' , 2 => 'nice' 3 => 'how');
$array2 = array (1 => 'there' , 2 => 'to' 3 => 'are');
$array3 = array (1 => 'champ' , 2 => 'meet' 3 => 'you');
我想输出一个字符串,它结合了每个数组的所有第一个键。 e.g:
echo "Hello there champ"
echo "nice to meet"
我该怎么做? 这些数组中的值总数将始终相同,因为这些值是从表中提取的。
提前致谢。
答案 0 :(得分:2)
echo $array1[1] . ' ' . $array2[1] . ' ' . $array3[1]; // hello there champ
echo $array1[2] . ' ' . $array2[2] . ' ' . $array3[2]; // nice to meet
答案 1 :(得分:1)
这样的东西?
function merge() {
$arrays = func_get_args();
$count = count($arrays[0]);
for ($i = 0; $i < $count; $i++) {
foreach ($arrays as $array) {
echo $array[$i];
}
echo "<br />";
}
}
$array1 = array (1 => 'helo' , 2 => 'nice' 3 => 'how');
$array2 = array (1 => 'there' , 2 => 'to' 3 => 'are');
$array3 = array (1 => 'champ' , 2 => 'meet' 3 => 'you');
merge($array1, $array2, $array3);
输出:
hello there champ<br />nice to meet<br />how are you<br />