1. 程式人生 > >php陣列面試題$arr1=array(1,2,3,4,5); $arr2=array('a','b','c','d','e');輸出要交叉輸出

php陣列面試題$arr1=array(1,2,3,4,5); $arr2=array('a','b','c','d','e');輸出要交叉輸出

<?php

$arr1=array(1,2,3,4,5);

$arr2=array('a','b','c','d','e');
for($i=0;$i<count($arr1);$i++)
{
echo $arr1[$i].$arr2[$i];
}





/*
$arr1=array(1,2,3,4,5);
$arr2=array('a','b','c','d','e');
$j=0;
$m=0;
for($i=1;$i<=(count($arr1)+count($arr2));$i++)
{
if($i%2!=0){
echo $arr1[$j];
$j++;
}
else
{
echo $arr2[$m];
$m++;
}
}
*/

/*
$arr1=array(1,2,3,4,5);
$arr2=array('a','b','c','d','e');
foreach($arr1 as $k=>$v)
{
echo$v;
foreach($arr2 as $k2=>$v2)
{
if($k==$k2)
{
echo $v2;
}
}

}

*/