0

我有 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');

我想输出一个字符串,它结合了每个数组的所有第一个键。例如:

 echo "Hello there champ"
 echo "nice to meet"

我怎样才能做到这一点?这些数组中的值的数量将始终相同,因为它们是从表中提取的。

提前致谢。

4

2 回答 2

2
echo $array1[1] . ' ' . $array2[1] . ' ' . $array3[1]; // hello there champ 
echo $array1[2] . ' ' . $array2[2] . ' ' . $array3[2]; // nice to meet 
于 2012-05-26T15:06:04.163 回答
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 />
于 2012-05-26T15:08:04.850 回答