本帖最后由 rosecshly0928 于 2013-09-09 12:44:58 编辑
predis 排序
我同事写的代码,他用predis存储我们的查询条件和查询结果,中途有更改我们的查询条件和查询结果,但是读出的值不是我想要的顺序,所有我就对结果进行了排序,排序后顺序是对了,但是在数组结尾处值就不对了。我不知道问题出在什么地方。
假如排序前结果是:
[471456_11_0_SGD_2013-11-26_2_2013-11-26] => Array ( [Error] => Unavailable [packagePr] => 0 [sequenceNo] => 11 [checkIn] => 2013-11-26 [checkOut] => 2013-11-26 [nights] => 0 [hotelName] => Own Arrangement )
[471444_12_2_SGD_2013-11-26_2_2013-11-28] => Array ( [sequenceNo] => 12 [Error] => Unavailable [packagePr] => 0 [checkIn] => 2013-11-26 [checkOut] => 2013-11-28 [nights] => 2 [hotelName] => Own Arrangement )
[471452_13_0_SGD_2013-11-28_2_2013-11-28] => Array ( [Error] => Unavailable [packagePr] => 0 [sequenceNo] => 13 [checkIn] => 2013-11-28 [checkOut] => 2013-11-28 [nights] => 0 [hotelName] => Own Arrangement )
[471442_14_1_SGD_2013-11-28_2_2013-11-29] => Array ( [sequenceNo] => 14 [Error] => Unavailable [packagePr] => 0 [checkIn] => 2013-11-28 [checkOut] => 2013-11-29 [nights] => 2 [hotelName] => Own Arrangement )
排序后结果可能是:[471456_11_0_SGD_2013-11-26_2_2013-11-26] => Array ( [Error] => Unavailable [packagePr] => 0 [sequenceNo] => 11 [checkIn] => 2013-11-26 [checkOut] => 2013-11-26 [nights] => 0 [hotelName] => Own Arrangement )
[471444_12_2_SGD_2013-11-26_2_2013-11-28] => Array ( [sequenceNo] => 12 [Error] => Unavailable [packagePr] => 0 [checkIn] => 2013-11-26 [checkOut] => 2013-11-28 [nights] => 2 [hotelName] => Own Arrangement )
[471452_13_0_SGD_2013-11-28_2_2013-11-28] => Array ( [Error] => Unavailable [packagePr] => 0 [sequenceNo] => 13 [checkIn] => 2013-11-28 [checkOut] => 2013-11-28 [nights] => 0 [hotelName] => Own Arrangement )
[471442_14_1_SGD_2013-11-28_2_2013-11-29] => Array ( [sequenceNo] => 14 [hotelName] => Flaminius [starRating] => 3 [hotelImage] => https://services.abc.com/images/hotels/d5da716c-b32c-4222-839d-3bb3a134007e.jpeg [hotelId] => 4157663 [localLocationId] => 0 [locationId] => 471442 [nights] => 1 [checkIn] => 2013-11-28 [checkOut] => 2013-11-29 [currencyCode] => SGD [supplierId] => 0 [packageId] => 92b6f8ce-b916-4653-aced-069c579493a3 [packagePr] => 100.09 [roomDetail] => Array ( [Room] => Array ( [AdultsCount] => 2 [Availability] => Available [Id] => 1adc296d-9fa9-4eb5-aa67-638f364bdeb6 [RoomBasis] => Bed and Breakfast BB [RoomClass] => Standard [RoomType] => Double ) ) [sessionId] => /88/1095/D20130909T042820/e72c9d41ec034a3a9daf1a57da9172ff )
我在想我排序也不可能把数组的值给改了,可是我只有删除了排序的代码出来出来的结果就是对的,一加上数组的值就不对。
我们设置查询条件和结果,更新查询条件和结果都是用的下面的函数:
public function setMkeyValue($args = array()){
if(!empty($args) && isset($args['setValue'])){
if(isset($args['keyprefix']) && $args['keyprefix'] != ''){
$this->setKeyPrefix($args['keyprefix']);
$this->newClientConnection();
}
$this->CLIENT->mset($args['setValue']);
}
}
public function setKeyPrefix($key_prefix = ''){
if($key_prefix != ''){
$this->KEY_PREFIX = $key_prefix;
}
}
回复讨论(解决方案)
你的数据数一个二维数组
你是如何排序的
你的数据数一个二维数组
你是如何排序的
我读sequence no,根据sequence no来放置:
$ordered_hotelSelection=Array();
for($i=1; $i<=count($hotelSelection); $i++){
foreach($hotelSelection as $key => $hotelInfo){
if(intval($hotelInfo['sequenceNo'])==$i){
$ordered_hotelSelection[$key]=$hotelSelection[$key];
}
}
}
return $ordered_hotelSelection;