时间:2021-07-01 10:21:17 帮助过:10人阅读
$arr1=array(1,2);
$arr2=array(3,4);
$res = test($arr1,$arr2,0,0);
echo "";";
print_r($res);
echo "
function test($arr1,$arr2,$index1=0,$index2=0) {
static $result = array();
$tmp[]=$arr1[$index1];
$tmp[]=$arr2[$index2];
$result [] = $tmp;
if(($index1==count($arr1)-1) && ($index2==count($arr2)-1)){
return $result;
}else{
if($index2==count($arr2)-1){
$index1++;
$index2 = 0;
}else{
$index2++;
}
return test($arr1,$arr2,$index1,$index2);
}
}
/*
Array
(
[0] => Array
(
[0] => 1
[1] => 3
)
[1] => Array
(
[0] => 1
[1] => 4
)
[2] => Array
(
[0] => 2
[1] => 3
)
[3] => Array
(
[0] => 2
[1] => 4
)
)
*/
$arr1 = array(1,2);
$arr2 = array(3,4);
$arr = array();
for($i=0,$max1=count($arr1); $i<$max1; $i++){
for($j=0,$max2=count($arr2); $j<$max2; $j++){
$tmp = array();
$tmp['arr1'] = $arr1[$i];
$tmp['arr2'] = $arr2[$j];
$arr[] = $tmp;
}
}
print_r($arr);