题库选项随机排序显示
When sorting an array, for example by using sort() there are three constants you can use to determine how the sorting will work:
在对数组进行排序时(例如,通过使用sort()),可以使用三个常量来确定排序的工作方式:
- SORT_REGULAR (default) when you have mixed types of variables in the array it won't cast them. The results can be ... hmm .. interesting. It will sort first all string types and them all numeric types SORT_REGULAR(默认),当您在数组中混合使用多种类型的变量时,将不会进行强制转换。 结果可能是...嗯..有趣。 它将首先对所有字符串类型和所有数字类型进行排序
- SORT_NUMERIC - all elements will be casted to their numeric valuesSORT_NUMERIC-所有元素都将强制转换为其数值
- SORT_STRING - all array elements will be sorted as strings.SORT_STRING-所有数组元素都将按字符串排序。
Here's an example of the three options:
这是三个选项的示例:
< ?php echo '
<?php echo'
';
$a = array(3, 1, '01', '011', '0001', 'a', 'a0', 'b0', '0b0', '1a1', '0a0', 'xyz', '99a', 991, '992');
sort($a, SORT_REGULAR); // default
print_r($a);
sort($a, SORT_NUMERIC);
print_r($a);
sort($a, SORT_STRING);
print_r($a);
?>
The result will be:
';
$a = array(3, 1, '01', '011', '0001', 'a', 'a0', 'b0', '0b0', '1a1', '0a0', 'xyz', '99a', 991, '992');
sort($a, SORT_REGULAR); // default
print_r($a);
sort($a, SORT_NUMERIC);
print_r($a);
sort($a, SORT_STRING);
print_r($a);
?>
The result will be:
题库选项随机排序显示