Return to asort_variation5.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / array |
1.1 misho 1: --TEST-- 2: Test asort() 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 asort ( array &$array [, int $asort_flags] ) 11: * Description: Sort an array and maintain index association 12: Elements will be arranged from lowest to highest when this function has completed. 13: * Source code: ext/standard/array.c 14: */ 15: 16: /* 17: * testing asort() 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 asort() : 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 asort() by supplying various string arrays --\n"; 43: 44: // loop through to test asort() 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(asort($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(asort($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 asort() : usage variations *** 67: 68: -- Testing asort() by supplying various string arrays -- 69: 70: -- Iteration 1 -- 71: - With default sort_flag - 72: bool(true) 73: array(12) { 74: ["null"]=> 75: NULL 76: ["NULL"]=> 77: NULL 78: [" "]=> 79: string(1) " " 80: [" 81: "]=> 82: string(1) " 83: " 84: [""]=> 85: string(1) "" 86: [""]=> 87: string(1) "" 88: [" "]=> 89: string(1) " " 90: ["\a"]=> 91: string(2) "\a" 92: ["\cx"]=> 93: string(3) "\cx" 94: ["\ddd"]=> 95: string(4) "\ddd" 96: ["\e"]=> 97: string(2) "\e" 98: ["\xhh"]=> 99: string(4) "\xhh" 100: } 101: - Sort_flag = SORT_REGULAR - 102: bool(true) 103: array(12) { 104: ["null"]=> 105: NULL 106: ["NULL"]=> 107: NULL 108: [" "]=> 109: string(1) " " 110: [" 111: "]=> 112: string(1) " 113: " 114: [""]=> 115: string(1) "" 116: [""]=> 117: string(1) "" 118: [" "]=> 119: string(1) " " 120: ["\a"]=> 121: string(2) "\a" 122: ["\cx"]=> 123: string(3) "\cx" 124: ["\ddd"]=> 125: string(4) "\ddd" 126: ["\e"]=> 127: string(2) "\e" 128: ["\xhh"]=> 129: string(4) "\xhh" 130: } 131: - Sort_flag = SORT_STRING - 132: bool(true) 133: array(12) { 134: ["null"]=> 135: NULL 136: ["NULL"]=> 137: NULL 138: [" "]=> 139: string(1) " " 140: [" 141: "]=> 142: string(1) " 143: " 144: [""]=> 145: string(1) "" 146: [""]=> 147: string(1) "" 148: [" "]=> 149: string(1) " " 150: ["\a"]=> 151: string(2) "\a" 152: ["\cx"]=> 153: string(3) "\cx" 154: ["\ddd"]=> 155: string(4) "\ddd" 156: ["\e"]=> 157: string(2) "\e" 158: ["\xhh"]=> 159: string(4) "\xhh" 160: } 161: 162: -- Iteration 2 -- 163: - With default sort_flag - 164: bool(true) 165: array(12) { 166: ["B"]=> 167: string(6) "BANANA" 168: ["O"]=> 169: string(6) "Orange" 170: ["T"]=> 171: string(4) "TTTT" 172: ["Te"]=> 173: string(4) "Test" 174: ["X"]=> 175: string(1) "X" 176: ["a"]=> 177: string(5) "apple" 178: ["b"]=> 179: string(6) "banana" 180: ["l"]=> 181: string(5) "lemoN" 182: ["o"]=> 183: string(6) "oraNGe" 184: ["t"]=> 185: string(3) "ttt" 186: ["w"]=> 187: string(2) "ww" 188: ["x"]=> 189: string(1) "x" 190: } 191: - Sort_flag = SORT_REGULAR - 192: bool(true) 193: array(12) { 194: ["B"]=> 195: string(6) "BANANA" 196: ["O"]=> 197: string(6) "Orange" 198: ["T"]=> 199: string(4) "TTTT" 200: ["Te"]=> 201: string(4) "Test" 202: ["X"]=> 203: string(1) "X" 204: ["a"]=> 205: string(5) "apple" 206: ["b"]=> 207: string(6) "banana" 208: ["l"]=> 209: string(5) "lemoN" 210: ["o"]=> 211: string(6) "oraNGe" 212: ["t"]=> 213: string(3) "ttt" 214: ["w"]=> 215: string(2) "ww" 216: ["x"]=> 217: string(1) "x" 218: } 219: - Sort_flag = SORT_STRING - 220: bool(true) 221: array(12) { 222: ["B"]=> 223: string(6) "BANANA" 224: ["O"]=> 225: string(6) "Orange" 226: ["T"]=> 227: string(4) "TTTT" 228: ["Te"]=> 229: string(4) "Test" 230: ["X"]=> 231: string(1) "X" 232: ["a"]=> 233: string(5) "apple" 234: ["b"]=> 235: string(6) "banana" 236: ["l"]=> 237: string(5) "lemoN" 238: ["o"]=> 239: string(6) "oraNGe" 240: ["t"]=> 241: string(3) "ttt" 242: ["w"]=> 243: string(2) "ww" 244: ["x"]=> 245: string(1) "x" 246: } 247: Done