1--TEST-- 2Test sort() function : basic functionality 3--FILE-- 4<?php 5/* Prototype : bool sort ( array &$array [, int $sort_flags] ) 6 * Description: This function sorts an array. 7 Elements will be arranged from lowest to highest when this function has completed. 8 * Source code: ext/standard/array.c 9*/ 10 11/* 12 * Testing sort() by providing arrays with default keys and assoc arrays 13 * to check the basic functionality with following flag values. 14 * flag value as defualt 15 * SORT_REGULAR - compare items normally 16 * SORT_NUMERIC - compare items numerically 17 * SORT_STRING - compare items as strings 18*/ 19 20echo "*** Testing sort() : basic functionality ***\n"; 21 22// associative array containing unsorted string values 23$unsorted_strings = array( "l" => "lemon", "o" => "orange", "b" => "banana" ); 24 25// array with default keys containing unsorted numeric values 26$unsorted_numerics = array( 100, 33, 555, 22 ); 27 28echo "\n-- Testing sort() by supplying string array, 'flag' value is defualt --\n"; 29$temp_array = $unsorted_strings; 30var_dump( sort($temp_array) ); // expecting : bool(true) 31var_dump( $temp_array); 32 33echo "\n-- Testing sort() by supplying numeric array, 'flag' value is defualt --\n"; 34$temp_array = $unsorted_numerics; 35var_dump( sort($temp_array) ); // expecting : bool(true) 36var_dump( $temp_array); 37 38echo "\n-- Testing sort() by supplying string array, 'flag' = SORT_REGULAR --\n"; 39$temp_array = $unsorted_strings; 40var_dump( sort($temp_array, SORT_REGULAR) ); // expecting : bool(true) 41var_dump( $temp_array); 42 43echo "\n-- Testing sort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; 44$temp_array = $unsorted_numerics; 45var_dump( sort($temp_array, SORT_REGULAR) ); // expecting : bool(true) 46var_dump( $temp_array); 47 48echo "\n-- Testing sort() by supplying string array, 'flag' = SORT_STRING --\n"; 49$temp_array = $unsorted_strings; 50var_dump( sort($temp_array, SORT_STRING) ); // expecting : bool(true) 51var_dump( $temp_array); 52 53echo "\n-- Testing sort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; 54$temp_array = $unsorted_numerics; 55var_dump( sort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) 56var_dump( $temp_array); 57 58echo "Done\n"; 59?> 60--EXPECTF-- 61*** Testing sort() : basic functionality *** 62 63-- Testing sort() by supplying string array, 'flag' value is defualt -- 64bool(true) 65array(3) { 66 [0]=> 67 string(6) "banana" 68 [1]=> 69 string(5) "lemon" 70 [2]=> 71 string(6) "orange" 72} 73 74-- Testing sort() by supplying numeric array, 'flag' value is defualt -- 75bool(true) 76array(4) { 77 [0]=> 78 int(22) 79 [1]=> 80 int(33) 81 [2]=> 82 int(100) 83 [3]=> 84 int(555) 85} 86 87-- Testing sort() by supplying string array, 'flag' = SORT_REGULAR -- 88bool(true) 89array(3) { 90 [0]=> 91 string(6) "banana" 92 [1]=> 93 string(5) "lemon" 94 [2]=> 95 string(6) "orange" 96} 97 98-- Testing sort() by supplying numeric array, 'flag' = SORT_REGULAR -- 99bool(true) 100array(4) { 101 [0]=> 102 int(22) 103 [1]=> 104 int(33) 105 [2]=> 106 int(100) 107 [3]=> 108 int(555) 109} 110 111-- Testing sort() by supplying string array, 'flag' = SORT_STRING -- 112bool(true) 113array(3) { 114 [0]=> 115 string(6) "banana" 116 [1]=> 117 string(5) "lemon" 118 [2]=> 119 string(6) "orange" 120} 121 122-- Testing sort() by supplying numeric array, 'flag' = SORT_NUMERIC -- 123bool(true) 124array(4) { 125 [0]=> 126 int(22) 127 [1]=> 128 int(33) 129 [2]=> 130 int(100) 131 [3]=> 132 int(555) 133} 134Done 135