php2个数组组合加减计算,PHP组合两个或多个数组

嗨大家我不能在PHP之间做.请帮我..

我有这些数组.

$arr1=[9,47]

$arr2=[15,113]

$arr3=[42,69]

//dynamically may be there is more or less array.

我想像这样创建数组,意味着在所有数组上组合每个值

//firstArray_firstValue, secondArray_firstValue, thirdArray_firstValue, ...

//firstArray_firstValue, secondArray_firstValue, thirdArray_secondValue, ...

//...

//firstArray_firstValue, secondArray_secondValue, thirdArray_firstValue, ...

//firstArray_firstValue, secondArray_secondValue, thirdArray_secondValue, ...

//...

//firstArray_secondValue, secondArray_firstValue, thirdArray_firstValue, ...

//firstArray_secondValue, secondArray_firstValue, thirdArray_secondValue, ...

//...

//firstArray_secondValue, secondArray_secondValue, thirdArray_firstValue, ...

//firstArray_secondValue, secondArray_secondValue, thirdArray_secondValue, ...

这些数组的示例结果

$resultArray = [

[9, 15, 42],

[9, 15, 69],

[9, 113, 42],

[9, 113, 69],

[47, 15, 42],

[47, 15, 69],

[47, 113, 42],

[47, 113, 69],

];

如何动态创建此结果?

最佳答案 这里是:

$arr1=[9,47];

$arr2=[15,113];

$arr3=[42,69];

foreach($arr1 as $a1)

foreach($arr2 as $a2)

foreach($arr3 as $a3)

$resultArray[] = [$a1, $a2, $a3];

print_r($resultArray);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值