【发布时间】:2018-12-05 15:13:55
【问题描述】:
大家好,我不能在 php 上做 betweens。请帮帮我..
我有这些数组。
$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],
];
如何动态创建此结果?
【问题讨论】:
-
您知道构建该结果的逻辑,对吗?因此,您可以尝试自己做一些事情。到目前为止,您尝试过什么?
-
您可能需要使用循环
-
试试 array_merge 或 array_map,也许其中一种对你有用。
-
@FelippeDuarte 我只尝试了 foreach 循环中的 foreach 循环。但我无法接近解决方案。我无法解决我应该建立什么样的结构。
-
@PatrickQ 谢谢。它解决了我的问题..