【发布时间】:2013-10-03 21:17:30
【问题描述】:
我有这个数组:(数组中的值总是偶数但大于8,数组值的一半也是偶数);
$array = array("apple", "banana", "pear", "grape", "cherry", "orange", "pineapple", "kiwi");
我想要的结果:
array(
[0] => array(apple => "banana", pear => "grape", cherry => "orange", pineapple => "kiwi"),
[1] => array(grape => "apple", banana => "pear", orange => "pineapple", kiwi => "cherry"),
...etc
[7] => array(banana => "apple", grape => "pear", orange => "cherry", kiwi => "pineapple"),
[8] => array(apple => "grape", pear => "banana", pineapple => "orange", cherry => "kiwi"),
...etc until [13]
)
如您所见,每个值有时是一个键,有时是一个值,除了相同的值外,所有可能的组合都必须进行(apple 与 apple 不能满足)。
如果第一次遇到[0]“apple”是key,下次遇到[1]应该是value
相同的两个值(苹果和香蕉)直到数组的最后一半才能再次相遇。
谁能帮我解决这个问题?
【问题讨论】:
-
我只在那里发现了部分问题,我最感兴趣的部分是
if the first encounter [0] "apple" is a key, in the next encounter [1] it should be a value The same two values ( apple and banana ) cannot meet again until the ending half of the array. -
我认为你可以有 64 种可能的组合。
-
其实没有,因为在苹果遇到香蕉的同一个数组结果值中,其他键也遇到了,计算所有的键+值组合是的,如果苹果遇到,可能有64-8或64苹果,但只计算主数组键,结果应该包含 14 个键,现在我说我注意到我写了 15。它应该从 0 到 13。
标签: php arrays combinations