16080891(Lamp→研讨会)
对数组重新排序(shuffle()和array_reverse())
上一篇 /
下一篇 2007-04-30 17:09:32
/ 个人分类:PHP学习笔记
1.shuffle():能够将数组打乱,进行随机排序. 2.array_reverse():接受数组array作为输入并返回一个元素内容完全相同,但是相反顺序的新数组.如果preserve_keys 为TURE则保留原来的键名. 例:
<?php
echo"随机排序数组:<br>";
$numbers = array(1,2,3,4,5);
shuffle($numbers); foreach($numbers as $numbers)
{
echo "$numbers";
}
$input = array("php",4.0,"hello");
$result =
array_reverse($input);
echo "<br>倒序排列:<br>";
print_r($result);
echo "<br>保持键值倒序排列:<br>";
$result_keyed =
array_reverse($input,ture);
print_r($result_keyed);
?>
输出结果:
随机排序数组:
53241
倒序排列:
Array
(
[0] => hello
[1] => 4
[2] => php
)
保持键值倒序排列:
Array
(
[2] => hello
[1] => 4
[0] => php
)
相关阅读:
- 预定义常量 (xile_php, 2007-4-29)
- 运算符优先级 (xile_php, 2007-4-29)
- break和continue语句 (xile_php, 2007-4-29)
- foreach语句的使用 (xile_php, 2007-4-30)
- 取出数组的部分元素(array_slice()) (xile_php, 2007-4-30)
- 删除数组元素(第一个和最后一个) (xile_php, 2007-4-30)
- array_unshift()和array_pust()函数插入元素 (xile_php, 2007-4-30)
- array_splice()函数替换元素 (xile_php, 2007-4-30)
- 浏览数组元素 (xile_php, 2007-4-30)
- 数组排序 (xile_php, 2007-4-30)
导入论坛
收藏
分享给好友
管理
举报
TAG:
PHP学习笔记