Annotation of embedaddon/php/ext/standard/tests/array/arsort_variation5.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test arsort() function : usage variations - sort strings
                      3: --SKIPIF--
                      4: <?php
                      5: if (substr(PHP_OS, 0, 3) == 'WIN') {
                      6:   die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)");
                      7: }
                      8: --FILE--
                      9: <?php
                     10: /* Prototype  : bool arsort ( array &$array [, int $asort_flags] )
                     11:  * Description: Sort an array and maintain index association 
                     12:                 Elements will be arranged from highest to lowest when this function has completed.
                     13:  * Source code: ext/standard/array.c
                     14: */
                     15: 
                     16: /*
                     17:  * testing arsort() by providing different string arrays for $array argument with following flag values
                     18:  *  flag value as defualt
                     19:  *  SORT_REGULAR - compare items normally
                     20:  *  SORT_STRING  - compare items as strings
                     21: */
                     22: 
                     23: echo "*** Testing arsort() : usage variations ***\n";
                     24: 
                     25: $various_arrays = array (
                     26:   // group of escape sequences 
                     27:   array ("null"=>  null, "NULL" => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", 
                     28:         "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", 
                     29:         "\ddd" => "\ddd", "\v" => "\v"
                     30:         ),
                     31: 
                     32:   // array contains combination of capital/small letters 
                     33:   array ('l' => "lemoN", 'O' => "Orange", 'b' => "banana", 'a' => "apple", 'Te' => "Test", 
                     34:         'T' => "TTTT", 't' => "ttt", 'w' => "ww", 'x' => "x", 'X' => "X", 'o' => "oraNGe",
                     35:         'B' => "BANANA"
                     36:         )
                     37: );
                     38: 
                     39: $flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING);
                     40: 
                     41: $count = 1;
                     42: echo "\n-- Testing arsort() by supplying various string arrays --\n";
                     43: 
                     44: // loop through to test arsort() with different arrays
                     45: foreach ($various_arrays as $array) {
                     46:   echo "\n-- Iteration $count --\n";
                     47: 
                     48:   echo "- With default sort_flag -\n";
                     49:   $temp_array = $array;
                     50:   var_dump(arsort($temp_array) ); // expecting : bool(true)
                     51:   var_dump($temp_array);
                     52: 
                     53:   // loop through $flags array and setting all possible flag values
                     54:   foreach($flags as $key => $flag){
                     55:     echo "- Sort_flag = $key -\n";
                     56:     $temp_array = $array;
                     57:     var_dump(arsort($temp_array, $flag) ); // expecting : bool(true)
                     58:     var_dump($temp_array);
                     59:   }
                     60:   $count++;
                     61: }
                     62: 
                     63: echo "Done\n";
                     64: ?>
                     65: --EXPECTF--
                     66: *** Testing arsort() : usage variations ***
                     67: 
                     68: -- Testing arsort() by supplying various string arrays --
                     69: 
                     70: -- Iteration 1 --
                     71: - With default sort_flag -
                     72: bool(true)
                     73: array(12) {
                     74:   ["\xhh"]=>
                     75:   string(4) "\xhh"
                     76:   ["\e"]=>
                     77:   string(2) "\e"
                     78:   ["\ddd"]=>
                     79:   string(4) "\ddd"
                     80:   ["\cx"]=>
                     81:   string(3) "\cx"
                     82:   ["\a"]=>
                     83:   string(2) "\a"
                     84:   ["
                     85: "]=>
                     86:   string(1) "
                     87: "
                     88:   [""]=>
                     89:   string(1) ""
                     90:   [""]=>
                     91:   string(1) ""
                     92:   ["
                     93: "]=>
                     94:   string(1) "
                     95: "
                     96:   ["   "]=>
                     97:   string(1) "  "
                     98:   ["null"]=>
                     99:   NULL
                    100:   ["NULL"]=>
                    101:   NULL
                    102: }
                    103: - Sort_flag = SORT_REGULAR -
                    104: bool(true)
                    105: array(12) {
                    106:   ["\xhh"]=>
                    107:   string(4) "\xhh"
                    108:   ["\e"]=>
                    109:   string(2) "\e"
                    110:   ["\ddd"]=>
                    111:   string(4) "\ddd"
                    112:   ["\cx"]=>
                    113:   string(3) "\cx"
                    114:   ["\a"]=>
                    115:   string(2) "\a"
                    116:   ["
                    117: "]=>
                    118:   string(1) "
                    119: "
                    120:   [""]=>
                    121:   string(1) ""
                    122:   [""]=>
                    123:   string(1) ""
                    124:   ["
                    125: "]=>
                    126:   string(1) "
                    127: "
                    128:   ["   "]=>
                    129:   string(1) "  "
                    130:   ["null"]=>
                    131:   NULL
                    132:   ["NULL"]=>
                    133:   NULL
                    134: }
                    135: - Sort_flag = SORT_STRING -
                    136: bool(true)
                    137: array(12) {
                    138:   ["\xhh"]=>
                    139:   string(4) "\xhh"
                    140:   ["\e"]=>
                    141:   string(2) "\e"
                    142:   ["\ddd"]=>
                    143:   string(4) "\ddd"
                    144:   ["\cx"]=>
                    145:   string(3) "\cx"
                    146:   ["\a"]=>
                    147:   string(2) "\a"
                    148:   ["
                    149: "]=>
                    150:   string(1) "
                    151: "
                    152:   [""]=>
                    153:   string(1) ""
                    154:   [""]=>
                    155:   string(1) ""
                    156:   ["
                    157: "]=>
                    158:   string(1) "
                    159: "
                    160:   ["   "]=>
                    161:   string(1) "  "
                    162:   ["null"]=>
                    163:   NULL
                    164:   ["NULL"]=>
                    165:   NULL
                    166: }
                    167: 
                    168: -- Iteration 2 --
                    169: - With default sort_flag -
                    170: bool(true)
                    171: array(12) {
                    172:   ["x"]=>
                    173:   string(1) "x"
                    174:   ["w"]=>
                    175:   string(2) "ww"
                    176:   ["t"]=>
                    177:   string(3) "ttt"
                    178:   ["o"]=>
                    179:   string(6) "oraNGe"
                    180:   ["l"]=>
                    181:   string(5) "lemoN"
                    182:   ["b"]=>
                    183:   string(6) "banana"
                    184:   ["a"]=>
                    185:   string(5) "apple"
                    186:   ["X"]=>
                    187:   string(1) "X"
                    188:   ["Te"]=>
                    189:   string(4) "Test"
                    190:   ["T"]=>
                    191:   string(4) "TTTT"
                    192:   ["O"]=>
                    193:   string(6) "Orange"
                    194:   ["B"]=>
                    195:   string(6) "BANANA"
                    196: }
                    197: - Sort_flag = SORT_REGULAR -
                    198: bool(true)
                    199: array(12) {
                    200:   ["x"]=>
                    201:   string(1) "x"
                    202:   ["w"]=>
                    203:   string(2) "ww"
                    204:   ["t"]=>
                    205:   string(3) "ttt"
                    206:   ["o"]=>
                    207:   string(6) "oraNGe"
                    208:   ["l"]=>
                    209:   string(5) "lemoN"
                    210:   ["b"]=>
                    211:   string(6) "banana"
                    212:   ["a"]=>
                    213:   string(5) "apple"
                    214:   ["X"]=>
                    215:   string(1) "X"
                    216:   ["Te"]=>
                    217:   string(4) "Test"
                    218:   ["T"]=>
                    219:   string(4) "TTTT"
                    220:   ["O"]=>
                    221:   string(6) "Orange"
                    222:   ["B"]=>
                    223:   string(6) "BANANA"
                    224: }
                    225: - Sort_flag = SORT_STRING -
                    226: bool(true)
                    227: array(12) {
                    228:   ["x"]=>
                    229:   string(1) "x"
                    230:   ["w"]=>
                    231:   string(2) "ww"
                    232:   ["t"]=>
                    233:   string(3) "ttt"
                    234:   ["o"]=>
                    235:   string(6) "oraNGe"
                    236:   ["l"]=>
                    237:   string(5) "lemoN"
                    238:   ["b"]=>
                    239:   string(6) "banana"
                    240:   ["a"]=>
                    241:   string(5) "apple"
                    242:   ["X"]=>
                    243:   string(1) "X"
                    244:   ["Te"]=>
                    245:   string(4) "Test"
                    246:   ["T"]=>
                    247:   string(4) "TTTT"
                    248:   ["O"]=>
                    249:   string(6) "Orange"
                    250:   ["B"]=>
                    251:   string(6) "BANANA"
                    252: }
                    253: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>