题库选项随机排序显示_数组排序选项

题库选项随机排序显示

题库选项随机排序显示

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 values

    SORT_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:

Tell your friends about this post on Facebook and Twitter

';
$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:

Tell your friends about this post on Facebook and Twitter

翻译自: https://www.phpied.com/array-sorting-options/

题库选项随机排序显示

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值