代码区项目交易流程

Random selection of a table in PHP


I have an array that has values like 1, 5, 6, 9, 11, 45, 56, etc. What I'm trying to do is to randomly one value, perhaps 6. Then I want to pick a random value excluding 6 (so no doubles). Then a random value excluding the last two, all from inside an array. Any help? I'm trying to do this without while loops but if they are necessary then so be it.

I suggest the following:

# pick a random key in your array $rand_key = array_rand($your_array); # extract the corresponding value $rand_value = $your_array[$rand_key]; # remove the key-value pair from the array unset($your_array[$rand_key]);

See: array_rand , unset .

本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师

点击收藏

LAST How security operations centers are adapting to the cloud era 「某课实战」Python Flask 高级编程 NEXT