dongqiyang3711 2017-03-30 01:47 采纳率: 100%
浏览 56

PHP x深度数组的所有可能组合

I have an array:

array(
  'ten' => array(
     0, => array('four', 'five', 'six'),
     1, => array('seventy', 'fourty', 'thirty')
  ),
  'twenty' => array(
     0, => array('four', 'five', 'six'),
     1, => array('seventy', 'fourty', 'thirty')
  ),
  'thirty' => array(
     0, => array('four', 'five', 'six'),
     1, => array('seventy', 'fourty', 'thirty')
  )
)

i would like to be able to come up with all unique 'leveled' combinations, so in this example i would end up with the following combinations

ten,four,seventy
ten,four,fourty
ten,four,thirty
ten,five,seventy
ten,five,fourty
ten,five,thirty
ten,six,seventy
ten,six,fourty
ten,six,thirty

enz. for the twenty and thirty "first keys".

i have tried to write some recursive loop, using for loops, while loops, and combined, but cant really figure it out, what i know is that there will always be a first level keyd "first number", so that will always be the first number in any combination, then the sublevels will be the same for each "First number", but the amount of children, and the amount of it's children are dynamic...

  • 写回答

0条回答 默认 最新

    报告相同问题?