title: Get all combinations using patterns and store to one array
body: <p>First of all you can get the array that i was working on here : </p>
  
  <p><em>File # 1:</em> Contains 1 hotel with 5rooms</p>
  
  <p><a href="https://drive.google.com/file/d/1XO6tMv0txfI2gLIrDYfy7jmXCPTWfIiC/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1XO6tMv0txfI2gLIrDYfy7jmXCPTWfIiC/view?usp=sharing</a></p>
  
  <p><em>File # 2:</em> Contains 104 hotels</p>
  
  <p><a href="https://drive.google.com/file/d/161SZ_ZP9NbcLUFvlFNaPNDmezmfHX8NI/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/161SZ_ZP9NbcLUFvlFNaPNDmezmfHX8NI/view?usp=sharing</a></p>
  
  <pre><code>index [accommodationInfo] = per hotel
  index [roomStay] = per room
  </code></pre>
  
  <p><em>Most likely related:</em></p>
  
  <p><a href="https://stackoverflow.com/questions/10834393/php-how-to-get-all-possible-combinations-of-1d-array">PHP: How to get all possible combinations of 1D array?</a>  </p>
  
  <p><strong>Please download file 1 and 2.</strong></p>
  
  <p><em>In file # 1.</em><br>
  Once you minimize each array you will get this kind of structure.</p>
  
  <p><em>Figure # 1</em></p>
  
  <pre><code>[indexes]
  [0]     =&gt; Array ...
  [1]     =&gt; Array ...
  [2]     =&gt; Array ...
  [3]     =&gt; Array ...
  [4]     =&gt; Array ...
  </code></pre>
  
  <p>each of this indexes you can see that they have requestedRoomIndex index inside of this array.</p>
  
  <p>you can see it in for example <code>[0]['roomInfo][requestedRoomIndex]</code> which has a value of 3.</p>
  
  <p>So i will ellaborate the <em>Figure # 1</em></p>
  
  <p><em>Figure # 1 (changed)</em></p>
  
  <pre><code>[index]                 [requestedRoomIndex]
  [0]     =&gt; Array ...        =&gt; 3,
  [1]     =&gt; Array ...        =&gt; 3,
  [2]     =&gt; Array ...        =&gt; 2,
  [3]     =&gt; Array ...        =&gt; 2,
  [4]     =&gt; Array ...        =&gt; 1
  </code></pre>
  
  <p><strong>I was added requestedRoomIndex in <em>figure # 1</em></strong> (i just get the different value of the requestedRoomIndex per indexes).</p>
  
  <p><strong>Here we will get the indexes that are paired by the Combination(123)</strong>:</p>
  
  <p>We get 4 which leads us to <em>431,430,421,420</em> indexes. </p>
  
  <p><strong>Why Combination is only 123?</strong></p>
  
  <p><em>- That is the only numbers that are seen in list of Figure # 1 [requestedRoomIndex] (changed)</em> of course it can be change once the request room was changed.</p>
  
  <p><strong>Pairedindexes = <em>431,430,421,420</em> (base in Combination)</strong></p>
  
  <p>Just to ellaborate more in my question at first: This is the request that i was send to the API</p>
  
  <pre><code>"requestBody":
  {
      "accommodationSubTypes":["Hotel","Motel"],
      "countryCode": "SGP",
      "cityCode": "SGP-SNGP000",
      "hotelCode": "",
      "checkIn": "2019-07-23",
      "checkOut": "2019-07-25",
      "paxNationality":"PH",
      "roomConfig": [{
          "adultCount": 1,
          "childAges": [5,12]
      },
      {
          "adultCount": 2,
          "childAges": []
      },
      {
          "adultCount": 1,
          "childAges": []
      }]
  }
  </code></pre>
  
  <p>keep on eye on roomConfig index. It contains of <strong>3</strong> array. </p>
  
  <p><strong>Room # 1</strong></p>
  
  <pre><code>{
      "adultCount": 1,
      "childAges": [5,12]
  }
  </code></pre>
  
  <p><strong>Room # 2</strong></p>
  
  <pre><code>{
      "adultCount": 2,
      "childAges": []
  }
  </code></pre>
  
  <p><strong>Room # 3</strong></p>
  
  <pre><code>{
      "adultCount": 1,
      "childAges": []
  }
  </code></pre>
  
  <p>*Combination = 123 (we have requested 3 rooms). Which indicates that i was requested a 3 room.**</p>
  
  <p>Fall down to <strong><em>(123) combinations</em></strong> base on their [requestedRoomIndex] value.</p>
  
  <p>As you can see this is only a 1 request on <strong>API</strong> </p>
  
  <p><strong>But the response given was divided according to their <code>[requestedRoomIndex]</code> value as you seen in Figure # 1 [index].</strong></p>
  
  <p>(Merging of rooms base in the Combination)</p>
  
  <p>We will count the generated <strong>(Pairedindexes)</strong>. </p>
  
  <p>(<strong><em>431,430,421,420</em> Pairedindexes</strong>)</p>
  
  <p>So this is how we get <strong>4 (Pairedindexes)</strong>.</p>
  
  <p><strong><em>Structure Result that i want to achieve:</em></strong></p>
  
  <pre><code>[0] =&gt; 
      {
          [the contents of the index 4 in our array ]
      },
      {
          [the contents of the index 3 in our array ]
      },
      {
          [the contents of the index 1 in our array ]
      },
  [1] =&gt; 
      {
          [the contents of the index 4 in our array ]
      },
      {
          [the contents of the index 2 in our array ]
      },
      {
          [the contents of the index 1 in our array ]
      },
  [2] =&gt; 
      {
          [the contents of the index 4 in our array ]
      },
      {
          [the contents of the index 3 in our array ]
      },
      {
          [the contents of the index 0 in our array ]
      },
  [3] =&gt; 
      {
          [the contents of the index 4 in our array ]
      },
      {
          [the contents of the index 2 in our array ]
      },
      {
          [the contents of the index 0 in our array ]
      },
  </code></pre>
  
  <p><strong>Which leads us to</strong></p>
  
  <pre><code>[Generated Paired Combination indexes]
  [0] =&gt; [{4},{3},{1}]
  [1] =&gt; [{4},{2},{1}]
  [2] =&gt; [{4},{3},{0}]
  [4] =&gt; [{4},{2},{0}]
  </code></pre>
  
  <p>I was hoping that i was deliver it clearly now. Thank you for any help. </p>