我试图取消/删除多维数据库中的一些元素以下代码,但我无法弄清楚如何。
我的数组看起来像(我的多维数组中只有两个元素)
[3] => stdClass Object
(
[processId] => H7-99440469
[hotelCode] => TR4SWV
[availabilityStatus] => InstantConfirmation
[totalPrice] => 36
[totalTax] => 0
[totalSalePrice] => 0
[currency] => EUR
[boardType] => All Inclusive
[rooms] => Array
(
[0] => stdClass Object
(
[roomCategory] => Double Promotional
[paxes] => Array
(
[0] => stdClass Object
(
[paxType] => Adult
[age] => 30
)
[1] => stdClass Object
(
[paxType] => Adult
[age] => 30
)
)
[totalRoomRate] => 36
[ratesPerNight] => Array
(
[0] => stdClass Object
(
[date] => 2015-05-01
[amount] => 36
)
)
)
)
)
[4] => stdClass Object
(
[processId] => HH-46795719
[hotelCode] => TRIIFY
[availabilityStatus] => InstantConfirmation
[specialDeal] => 11
[totalPrice] => 38
[totalTax] => 0
[totalSalePrice] => 0
[currency] => EUR
[boardType] => All Inc.
[rooms] => Array
(
[0] => stdClass Object
(
[roomCategory] => Double Room
[paxes] => Array
(
[0] => stdClass Object
(
[paxType] => Adult
[age] => 30
)
[1] => stdClass Object
(
[paxType] => Adult
[age] => 30
)
)
[totalRoomRate] => 38
[ratesPerNight] => Array
(
[0] => stdClass Object
(
[date] => 2015-05-01
[amount] => 38
)
)
)
)
)
如何删除所有没有的元素[specialDeal] => 11? [specialDeal] => 11是提前预订折扣
答案 0 :(得分:-1)
for($i=0;$i<count($array);$i++) {
if (!(isset($array[$i]->specialDeal) && $array[$i]->specialDeal] === 11)) {
unset($array[$i]);
}
}
答案 1 :(得分:-1)
$otherspecialoffer = array();
foreach( $availHotels as $key=>$item ) {
if (!(isset($item->specialDeal) && $item->specialDeal === 11)) {
unset($availHotels[$key]);
} else {
$otherspecialoffer[$item->specialDeal] = $key;
}
}