0

私はこのスクリプトを持っています

$todos=array(
    '0' => array('id' => 46, 'nombre' => 'b2 miami downtown','precio' => 149.01,'tipo' => 'expedia'),
    '1' => array('id' => 242,'nombre' => 'b2 Miami Downtown','precio' => 176.98,'tipo' => 'hotelbeds'),
    '2' => array('id' => 240,'nombre' => 'b2 Miami Downtown','precio' => 131.62,'tipo' => 'hotelbeds'),
    '3' => array('id' => 241,'nombre' => 'b2 Miami Downtown','precio' => 131.62,'tipo' => 'hotelbeds'),
    '4' => array( 'id' => 178,'nombre' => 'Z Ocean Hotel South Beach','precio' => 400.93,'tipo' => 'expedia'),
    '5' => array( 'id' => 254,'nombre' => 'Whitelaw Hotel','precio' => 142.29,'tipo' => 'hotelbeds'),
    '6' => array( 'id' => 124, 'nombre' => 'Whitelaw Hotel','precio' => 132.04,'tipo' => 'tourico'),
    '7' => array( 'id' => 62, 'nombre' => 'Westin Colonnade Coral Gables','precio' => 138.39,'tipo' => 'tourico'),
    '8' => array( 'id' => 275, 'nombre' => 'Westgate South Beach','precio' => 166.79,'tipo' => 'hotelbeds'),
    '9' => array( 'id' => 44, 'nombre' => 'W South Beach','precio' => 374.55,'tipo' => 'tourico'),
    '10' => array( 'id' => 206, 'nombre' => 'Holiday Inn Express West Doral Miami Airport','precio' => 103.22,'tipo' => 'hotelbeds'),
    '11' => array( 'id' => 117, 'nombre' => 'Holiday Inn Express Miami International Airport','precio' => 106.3,'tipo' => 'expedia'),
    '12' => array( 'id' => 114, 'nombre' => 'Holiday Inn Express Miami Airport Doral Area','precio' => 113,'tipo' => 'tourico'),
    '13' => array( 'id' => 78, 'nombre' => 'Holiday Inn Express Doral','precio' => 93.36,'tipo' => 'expedia'),
    '14' => array( 'id' => 62, 'nombre' => 'Holiday Inn Express & Suites Kendall East Miami','precio' => 128.46,'tipo' => 'expedia'),
    '15' => array( 'id' => 18, 'nombre' => 'Best Western Plus Kendall Hotel & Suites','precio' => 429.55,'tipo' => 'tourico'),
    '16' => array( 'id' => 19, 'nombre' => 'Best Western Plus Kendall Hotel & Suites','precio' => 429.55,'tipo' => 'expedia'),
    '17' => array( 'id' => 120, 'nombre' => 'Best Western Kendall Hotel & Suites','precio' => 114.27,'tipo' => 'expedia'),
    '18' => array( 'id' => 69, 'nombre' => 'Holiday Inn Express & Suites Kendall','precio' => 126.5,'tipo' => 'expedia'));

    echo "<pre>";
    print_r($todos);

    function comp($a,$b){
        if(soundex($a['nombre'])==soundex($b['nombre'])) return($a['precio']-$b['precio']);
        if(soundex($a['nombre'])!=soundex($b['nombre'])) return strcmp($a['nombre'], $b['nombre']);
    }
    usort($todos,'comp');
    print_r($todos);
    echo "<pre>";

配列を最初にホテル名で並べ替え、次に各ホテルを価格 (precio) で並べ替える必要があります。soundexを使用する理由は、同じホテルでもプロバイダー (提供者) によって名前が異なる可能性があるためです。そのため、ホテルをグループ化し、最低価格を最初に置き、他のホテルを削除して、最高のホテルのみを提供できるようにする必要があります。価格。

出力:

Array
(
   [0] => Array
        (
            [id] => 46
            [nombre] => b2 miami downtown
            [precio] => 149.01
            [tipo] => expedia
        )

    [1] => Array
        (
            [id] => 242
            [nombre] => b2 Miami Downtown
            [precio] => 176.98
            [tipo] => hotelbeds
        )

    [2] => Array
        (
            [id] => 240
            [nombre] => b2 Miami Downtown
            [precio] => 131.62
            [tipo] => hotelbeds
        )

    [3] => Array
        (
            [id] => 241
            [nombre] => b2 Miami Downtown
            [precio] => 131.62
            [tipo] => hotelbeds
        )

    [4] => Array
        (
            [id] => 178
            [nombre] => Z Ocean Hotel South Beach
            [precio] => 400.93
            [tipo] => expedia
        )

    [5] => Array
        (
            [id] => 254
            [nombre] => Whitelaw Hotel
            [precio] => 142.29
            [tipo] => hotelbeds
        )

    [6] => Array
        (
            [id] => 124
            [nombre] => Whitelaw Hotel
            [precio] => 132.04
            [tipo] => tourico
        )

    [7] => Array
        (
            [id] => 62
            [nombre] => Westin Colonnade Coral Gables
            [precio] => 138.39
            [tipo] => tourico
        )

    [8] => Array
        (
            [id] => 275
            [nombre] => Westgate South Beach
            [precio] => 166.79
            [tipo] => hotelbeds
        )

    [9] => Array
        (
            [id] => 44
            [nombre] => W South Beach
            [precio] => 374.55
            [tipo] => tourico
        )

    [10] => Array
        (
            [id] => 206
            [nombre] => Holiday Inn Express West Doral Miami Airport
            [precio] => 103.22
            [tipo] => hotelbeds
        )

    [11] => Array
        (
            [id] => 117
            [nombre] => Holiday Inn Express Miami International Airport
            [precio] => 106.3
            [tipo] => expedia
        )

    [12] => Array
        (
            [id] => 114
            [nombre] => Holiday Inn Express Miami Airport Doral Area
            [precio] => 113
            [tipo] => tourico
        )

    [13] => Array
        (
            [id] => 78
            [nombre] => Holiday Inn Express Doral
            [precio] => 93.36
            [tipo] => expedia
        )

    [14] => Array
        (
            [id] => 62
            [nombre] => Holiday Inn Express & Suites Kendall East Miami
            [precio] => 128.46
            [tipo] => expedia
        )

    [15] => Array
        (
            [id] => 18
            [nombre] => Best Western Plus Kendall Hotel & Suites
            [precio] => 429.55
            [tipo] => tourico
        )

    [16] => Array
        (
            [id] => 19
            [nombre] => Best Western Plus Kendall Hotel & Suites
            [precio] => 429.55
            [tipo] => expedia
        )

    [17] => Array
        (
            [id] => 120
            [nombre] => Best Western Kendall Hotel & Suites
            [precio] => 114.27
            [tipo] => expedia
        )

    [18] => Array
        (
            [id] => 69
            [nombre] => Holiday Inn Express & Suites Kendall
            [precio] => 126.5
            [tipo] => expedia
        )

)

ソートされた配列

Array
(
    [0] => Array
        (
            [id] => 120
            [nombre] => Best Western Kendall Hotel & Suites
            [precio] => 114.27
            [tipo] => expedia
        )

    [1] => Array
        (
            [id] => 19
            [nombre] => Best Western Plus Kendall Hotel & Suites
            [precio] => 429.55
            [tipo] => expedia
        )

    [2] => Array
        (
            [id] => 18
            [nombre] => Best Western Plus Kendall Hotel & Suites
            [precio] => 429.55
            [tipo] => tourico
        )

    [3] => Array
        (
            [id] => 78
            [nombre] => Holiday Inn Express Doral
            [precio] => 93.36
            [tipo] => expedia
        )

    [4] => Array
        (
            [id] => 206
            [nombre] => Holiday Inn Express West Doral Miami Airport
            [precio] => 103.22
            [tipo] => hotelbeds
        )

    [5] => Array
        (
            [id] => 117
            [nombre] => Holiday Inn Express Miami International Airport
            [precio] => 106.3
            [tipo] => expedia
        )

    [6] => Array
        (
            [id] => 114
            [nombre] => Holiday Inn Express Miami Airport Doral Area
            [precio] => 113
            [tipo] => tourico
        )

    [7] => Array
        (
            [id] => 69
            [nombre] => Holiday Inn Express & Suites Kendall
            [precio] => 126.5
            [tipo] => expedia
        )

    [8] => Array
        (
            [id] => 62
            [nombre] => Holiday Inn Express & Suites Kendall East Miami
            [precio] => 128.46
            [tipo] => expedia
        )

    [9] => Array
        (
            [id] => 44
            [nombre] => W South Beach
            [precio] => 374.55
            [tipo] => tourico
        )

    [10] => Array
        (
            [id] => 275
            [nombre] => Westgate South Beach
            [precio] => 166.79
            [tipo] => hotelbeds
        )

    [11] => Array
        (
            [id] => 62
            [nombre] => Westin Colonnade Coral Gables
            [precio] => 138.39
            [tipo] => tourico
        )

    [12] => Array
        (
            [id] => 124
            [nombre] => Whitelaw Hotel
            [precio] => 132.04
            [tipo] => tourico
        )

    [13] => Array
        (
            [id] => 254
            [nombre] => Whitelaw Hotel
            [precio] => 142.29
            [tipo] => hotelbeds
        )

    [14] => Array
        (
            [id] => 178
            [nombre] => Z Ocean Hotel South Beach
            [precio] => 400.93
            [tipo] => expedia
        )

    [15] => Array
        (
            [id] => 240
            [nombre] => b2 Miami Downtown
            [precio] => 131.62
            [tipo] => hotelbeds
        )

    [16] => Array
        (
            [id] => 241
            [nombre] => b2 Miami Downtown
            [precio] => 131.62
            [tipo] => hotelbeds
        )

    [17] => Array
        (
            [id] => 46
            [nombre] => b2 miami downtown
            [precio] => 149.01
            [tipo] => expedia
        )

    [18] => Array
        (
            [id] => 242
            [nombre] => b2 Miami Downtown
            [precio] => 176.98
            [tipo] => hotelbeds
        )

)

ご覧のとおり、"b2 Miami Downtown" は最後ではなく配列の一番上にあるはずです。

これを手伝ってください。

ありがとう!!!。

4

1 に答える 1

3

strcmpの PHP マニュアルから:

この比較では大文字と小文字が区別されることに注意してください。

AZ の文字は、 az の文字の前に来ます。代わりにstrcasecmpを試してください。

編集: strcasecmp を使用している場合でも、大文字と小文字を区別しないということは実際には英語の文字セットにのみ適用されることに注意してください。他のロケール (スペイン語、フランス語、ドイツ語など) で名前を使用する場合、これらの非基本 ASCII 文字は引き続きバイナリ方式で比較されます。例えば、

posada el Ñandú rengoと同等ではありませんposada el ñandÚ rengo

比較する前に、mb_convert_case や mb_strtolower などのマルチバイト文字列関数を使用することをお勧めします。

于 2013-07-24T14:16:59.370 に答える