php从数组中随机筛选出指定个数的值
2021/10/9 12:18:30
本文主要是介绍php从数组中随机筛选出指定个数的值,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
function uni($array,$nums,$unique=true){ $newarray=array(); if((bool)$unique){ $array=array_unique($array);// 移除数组中重复的值,并且返回数组。 } if(shuffle($array)){// 打乱数组 for ($i=0; $i <$nums ; $i++) { if(in_array($array[$i],$newarray)){ $nums++; }else{ $newarray[]=$array[$i]; } } } return $newarray; } $arr=[1,2,3,4,5,6,7,8,9,10]; $re=uni($arr,3); var_dump($re);
这篇关于php从数组中随机筛选出指定个数的值的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-30百度空间安装易优,如何去除URL中的index.php-icode9专业技术文章分享
- 2024-06-30宝塔Linux服务器隐藏index.php-icode9专业技术文章分享
- 2024-03-29env: php: no such file or directory
- 2024-03-01php foreach break
- 2024-02-26Exception参数 php-icode9专业技术文章分享
- 2023-12-30PHP文件批量上传-icode9专业技术文章分享
- 2023-12-30thinkphp6 withJoin-icode9专业技术文章分享
- 2023-12-27MagicArray:像php一样,让Go业务代码不再卷!
- 2023-11-18centos7编译安装PHP教程。
- 2023-11-18centos7编译安装phpMyAdmin教程。