排序在多维数组中无法正常工作

时间:2016-01-28 05:08:24

标签: php arrays sorting multidimensional-array

我正在对多维数组中的数据进行排序,但是当我尝试排序时,它无法正常工作。我正在排序,如果房间名称相等,那么检查它的费率计划,如果它们相等,那么检查率,我们有显示最低房价和所有其他剩余房间

        $arr1  =   array(
            array (
                          'hotelId'  => '10',
                        'roomId'  => '10',
                        'whotel' =>'0',
                        'roomName' => 'Standard',
                        'ratePlan' => 'CPAI',
                        'roomRate' => 11000
                    ),
              **array
                    (
                        'hotelId'  => '10',
                        'roomId'  => '10',
                        'whotel' =>'0',
                        'roomName' => 'test',
                        'ratePlan' => 'MAP',
                        'roomRate' => 10000
                    )**,
            array
                    (
                        'hotelId'  => '10',
                        'roomId'  => '10',
                        'whotel' =>'0',
                        'roomName' => 'test123',
                        'ratePlan' => 'CP',
                        'roomRate' => 10000
                    ),
            array
                    (
                        'hotelId'  => '10',
                        'roomId'  => '10',
                        'whotel' =>'0',
                        'roomName' => 'test',
                        'ratePlan' => 'MAP',
                        'roomRate' => 10000
                    )        

            );
    $arr2  =   array(
        **array (
                      'hotelId'  => '10',
                    'roomId'  => '10',
                    'whotel' =>'1',
                    'roomName' => 'Standard',
                    'ratePlan' => 'CPAI',
                    'roomRate' => 12000
                ),**
          array
                (
                    'hotelId'  => '10',
                    'roomId'  => '10',
                    'whotel' =>'1',
                    'roomName' => 'Honeymoon',
                    'ratePlan' => 'MAP',
                    'roomRate' => 10800
                ),

                array
                (
                    'hotelId'  => '10',
                    'roomId'  => '10',
                    'whotel' =>'1',
                    'roomName' => 'test123',
                    'ratePlan' => 'CP',
                    'roomRate' => 9000
                ),
                array
                (
                    'hotelId'  => '10',
                    'roomId'  => '10',
                    'whotel' =>'1',
                    'roomName' => 'waff',
                    'ratePlan' => 'MAP',
                    'roomRate' => 10800
                ));
this array can be increasing i wrote following code

$data123 = array_merge($arr1,$arr2);
//print_r($data123);
$output = array();
foreach($data123 as $arr){
$output [$arr['hotelId']][$arr['roomId']][$arr['whotel']][$arr['roomName']][$arr['ratePlan']][][] = [$arr['roomRate']];
sort($output[$arr['ratePlan']][$arr['roomRate']]);
}
print_R($output);
die;
//deassemble
$data = array();

foreach($output as $hotelId=>$arr1)
{
    foreach($arr1 as $roomId=>$arr2)
    {
        foreach($arr2 as $whotel=>$arr3)
        {
            foreach($arr3 as $roomName=>$arr4)
            {
                foreach($arr4 as $ratePlan=>$arr5)
                {
                    foreach($arr5 as $roomRate=>$arr6)
                    {    
                            $data[] = array(    
                            'hotelId' => $hotelId,
                            'whotel' => $whotel,
                            'roomId' => $roomId,
                            'roomName' => $roomName,
                            'ratePlan' => $ratePlan,
                            'roomRate' => $arr5[0],

                            );
                    }
                }
            }
        }   
    }    
}

print_R($data);

但是没有正确排序数据我希望输出像上面的数组有两个标准间检查他们的计划如果计划相等那么检查率在这11000最小所以显示房间和其他剩余房间

我想要输出如下

$output = 
 array(
    array (
                  'hotelId'  => '10',
                'roomId'  => '10',
                'whotel' =>'0',
                'roomName' => 'Standard',
                'ratePlan' => 'CPAI',
                'roomRate' => 11000
           ),
     array
            (
                'hotelId'  => '10',
                'roomId'  => '10',
                'whotel' =>'0',
                'roomName' => 'test',
                'ratePlan' => 'MAP',
                'roomRate' => 10000
            )          
        ),
        array
            (
                'hotelId'  => '10',
                'roomId'  => '10',
                'whotel' =>'1',
                'roomName' => 'Honeymoon',
                'ratePlan' => 'MAP',
                'roomRate' => 10800
            ),

            array
            (
                'hotelId'  => '10',
                'roomId'  => '10',
                'whotel' =>'1',
                'roomName' => 'test123',
                'ratePlan' => 'CP',
                'roomRate' => 9000
            ),
            array
            (
                'hotelId'  => '10',
                'roomId'  => '10',
                'whotel' =>'1',
                'roomName' => 'waff',
                'ratePlan' => 'MAP',
                'roomRate' => 10800
            ));

不包括大胆的房间

0 个答案:

没有答案