get random value from a PHP array, but make it unique

后端 未结 9 1115
挽巷
挽巷 2020-12-16 19:44

I want to select a random value from a array, but keep it unique as long as possible.

For example if I\'m selecting a value 4 times from a array of 4 elements, the s

9条回答
  •  甜味超标
    2020-12-16 20:38

    You almost have it right. The problem was the unset($arr_history[$selected]); line. The value of $selected isn't a key but in fact a value so the unset wouldn't work.

    To keep it the same as what you have up there:

    Or an example with a few less lines:

提交回复
热议问题