我需要整理一个数组。并将所有类似的信息收集在一起。
这将是我提出的一个巨大订单,但是,它远远超出了我的技能范围,我已经尝试修复它 3 天。
该消息来自一个网络服务,我完全无法控制输出/响应。
我需要能够放置所有信息但以下(我知道它很抱歉)是 SOAP 对象回复:(这也已减少)eek。
[0] => RoomInformation Object
(
[Details] => DetailsType Object
(
[Total] => TotalType Object
(
[AmountAfterTax] => 1.00
)
[EffectiveDate] => 2011-08-12
[AvailabilityStatus] => AvailableForSale
)
[RoomInformationExtend] => TPA_ExtensionsType Object
(
[RoomDetails] => RoomDetails Object
(
[RoomId] => 1860
[RoomNo] => THAH01
[Description] => Hotel Alpha
)
)
)
[1] => RoomInformation Object
(
[Details] => DetailsType Object
(
[RoomRate] => RoomRateType Object
(
[Total] => TotalType Object
(
[AmountAfterTax] => 1.00
)
[EffectiveDate] => 2011-08-12
[AvailabilityStatus] => AvailableForSale
)
)
[RoomInformationExtend] => TPA_ExtensionsType Object
(
[RoomDetails] => RoomDetails Object
(
[RoomId] => 1861
[RoomNo] => THAH02
[Description] => Hotel Alpha
)
)
)
[2] => RoomInformation Object
(
[Details] => DetailsType Object
(
[RoomRate] => RoomRateType Object
(
[Total] => TotalType Object
(
[AmountAfterTax] => 1.00
)
[EffectiveDate] => 2011-08-12
[AvailabilityStatus] => AvailableForSale
)
)
[RoomInformationExtend] => TPA_ExtensionsType Object
(
[RoomDetails] => RoomDetails Object
(
[Amenities] => stdClass Object
(
)
[Configurations] => stdClass Object
(
)
[RoomId] => 1226
[RoomNo] => DENM01
[Description] => Hotel Beta
)
)
)
[3] => RoomInformation Object
(
[Details] => DetailsType Object
(
[RoomRate] => RoomRateType Object
(
[Total] => TotalType Object
(
[AmountAfterTax] => 1.00
)
[EffectiveDate] => 2011-08-12
[AvailabilityStatus] => AvailableForSale
)
[MoreRatesExistInd] =>
)
[RoomInformationExtend] => TPA_ExtensionsType Object
(
[RoomDetails] => RoomDetails Object
(
[Amenities] => stdClass Object
(
)
[Configurations] => stdClass Object
(
)
[RoomId] => 1227
[RoomNo] => DENM02
[Description] => Hotel Beta
)
)
)
[4] => RoomInformation Object
(
[Details] => DetailsType Object
(
[Total] => TotalType Object
(
[AmountAfterTax] => 1.00
)
[EffectiveDate] => 2011-08-13
[AvailabilityStatus] => AvailableForSale
)
[RoomInformationExtend] => TPA_ExtensionsType Object
(
[RoomDetails] => RoomDetails Object
(
[RoomId] => 1860
[RoomNo] => THAH01
[Description] => Hotel Alpha
)
)
)
[5] => RoomInformation Object
(
[Details] => DetailsType Object
(
[RoomRate] => RoomRateType Object
(
[Total] => TotalType Object
(
[AmountAfterTax] => 1.00
)
[EffectiveDate] => 2011-08-13
[AvailabilityStatus] => AvailableForSale
)
)
[RoomInformationExtend] => TPA_ExtensionsType Object
(
[RoomDetails] => RoomDetails Object
(
[RoomId] => 1861
[RoomNo] => THAH02
[Description] => Hotel Alpha
)
)
)
[2] => RoomInformation Object
(
[Details] => DetailsType Object
(
[RoomRate] => RoomRateType Object
(
[Total] => TotalType Object
(
[AmountAfterTax] => 1.00
)
[EffectiveDate] => 2011-08-13
[AvailabilityStatus] => AvailableForSale
)
)
[RoomInformationExtend] => TPA_ExtensionsType Object
(
[RoomDetails] => RoomDetails Object
(
[Amenities] => stdClass Object
(
)
[Configurations] => stdClass Object
(
)
[RoomId] => 1226
[RoomNo] => DENM01
[Description] => Hotel Beta
)
)
)
[3] => RoomInformation Object
(
[Details] => DetailsType Object
(
[RoomRate] => RoomRateType Object
(
[Total] => TotalType Object
(
[AmountAfterTax] => 1.00
)
[EffectiveDate] => 2011-08-13
[AvailabilityStatus] => AvailableForSale
)
[MoreRatesExistInd] =>
)
[RoomInformationExtend] => TPA_ExtensionsType Object
(
[RoomDetails] => RoomDetails Object
(
[Amenities] => stdClass Object
(
)
[Configurations] => stdClass Object
(
)
[RoomId] => 1227
[RoomNo] => DENM02
[Description] => Hotel Beta
)
)
)
TL;博士
每家酒店都有 2 间带身份证的房间。这 2 个 id 中的每一个都由日期分隔,但位于数组的不同部分:(
[Hotel A]
HotelA RoomId = 01
Date = 12-08-2011
[Hotel A]
HotelA RoomId = 02
Date = 12-08-2011
[Hotel B]
HotelB RoomId = 01
Date = 12-08-2011
[Hotel B]
HotelB RoomId = 02
Date = 12-08-2011
[Hotel A]
HotelA RoomId = 01
Date = 13-08-2011
[Hotel A]
HotelA RoomId = 02
Date = 13-08-2011
[Hotel B]
HotelB RoomId = 01
Date = 13-08-2011
[Hotel B]
HotelB RoomId = 02
Date = 13-08-2011
我希望能够将它们放入这样的数组中:
[Hotel A]
HotelA RoomId = 01
Date 12-08-2011
Date 13-08-2011
HotelA RoomId = 02
Date 12-08-2011
Date 13-08-2011
ETC
请帮忙。我一直在拔头发:(
这是我尝试过的示例:
$hotelinfo = array();
$k=0;
for($i = 0; $i < count($result->RoomInformation); $i++)
{
$flag = false;
$HotelObj = $result->RoomInformation[$i];
$HotelName = $result->RoomInformation[$i]->RoomInformationExtend->RoomDetails->Description;
$HotelId = $result->RoomStays->RoomStay[$i]->RoomInformation->RoomDetails->RoomId;
//$hotelinfo[$i][$HotelName] = array();
$hotelinfo[count($hotelinfo)] = array();
$hotelinfo[count($hotelinfo)][$HotelName] = array();
for($c = 0; $c < count($result->RoomInformation); $c++)
{
$thishotelObj = $result->RRoomInformation[$c];
$thisHotelName = $thishotelObj->RoomInformationExtend->RoomDetails->Description;
$thisHotelId = $thishotelObj->TPA_Extensions->RoomDetails->RoomId;
if($thisHotelName == $HotelName & $thisHotelId == $HotelId){
$hotelinfo[$i][$HotelName][$c] = $HotelName;
$hotelinfo[$i][$HotelName][$c] = $thisHotelName;
$i++;
}
}
}
我什至朝着正确的方向前进吗?