First of all you can get the array that i was working on here :
File # 1: Contains 1 hotel with 5rooms
https://drive.google.com/file/d/1XO6tMv0txfI2gLIrDYfy7jmXCPTWfIiC/view?usp=sharing
File # 2: Contains 104 hotels
https://drive.google.com/file/d/161SZ_ZP9NbcLUFvlFNaPNDmezmfHX8NI/view?usp=sharing
index [accommodationInfo] = per hotel
index [roomStay] = per room
Most likely related:
PHP: How to get all possible combinations of 1D array?
Please download file 1 and 2.
In file # 1.
Once you minimize each array you will get this kind of structure.
Figure # 1
[indexes]
[0] => Array ...
[1] => Array ...
[2] => Array ...
[3] => Array ...
[4] => Array ...
each of this indexes you can see that they have requestedRoomIndex index inside of this array.
you can see it in for example [0]['roomInfo][requestedRoomIndex]
which has a value of 3.
So i will ellaborate the Figure # 1
Figure # 1 (changed)
[index] [requestedRoomIndex]
[0] => Array ... => 3,
[1] => Array ... => 3,
[2] => Array ... => 2,
[3] => Array ... => 2,
[4] => Array ... => 1
I was added requestedRoomIndex in figure # 1 (i just get the different value of the requestedRoomIndex per indexes).
Here we will get the indexes that are paired by the Combination(123):
We get 4 which leads us to 431,430,421,420 indexes.
Why Combination is only 123?
- That is the only numbers that are seen in list of Figure # 1 [requestedRoomIndex] (changed) of course it can be change once the request room was changed.
Pairedindexes = 431,430,421,420 (base in Combination)
Just to ellaborate more in my question at first: This is the request that i was send to the API
"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": []
}]
}
keep on eye on roomConfig index. It contains of 3 array.
Room # 1
{
"adultCount": 1,
"childAges": [5,12]
}
Room # 2
{
"adultCount": 2,
"childAges": []
}
Room # 3
{
"adultCount": 1,
"childAges": []
}
*Combination = 123 (we have requested 3 rooms). Which indicates that i was requested a 3 room.**
Fall down to (123) combinations base on their [requestedRoomIndex] value.
As you can see this is only a 1 request on API
But the response given was divided according to their [requestedRoomIndex]
value as you seen in Figure # 1 [index].
(Merging of rooms base in the Combination)
We will count the generated (Pairedindexes).
(431,430,421,420 Pairedindexes)
So this is how we get 4 (Pairedindexes).
Structure Result that i want to achieve:
[0] =>
{
[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] =>
{
[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] =>
{
[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] =>
{
[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 ]
},
Which leads us to
[Generated Paired Combination indexes]
[0] => [{4},{3},{1}]
[1] => [{4},{2},{1}]
[2] => [{4},{3},{0}]
[4] => [{4},{2},{0}]
I was hoping that i was deliver it clearly now. Thank you for any help.