Paste a piece of code. You don't need to say much about getting random arrays in php. Directly paste the code. The array_rand in php is abnormal. It breaks through normal people's understanding and is tedious.
Example 1
The code is as follows: |
Copy code |
Function create_random_ids ($ min, $ max, $ limited) { $ _ Base_ids = range ($ min, $ max ); $ _ Temp_key = array_rand ($ _ base_ids, min (count ($ _ base_ids), $ limited + 10 )); // Splicing $ Ids = array (); For ($ x = 0; $ x <count ($ _ temp_key); $ x ++ ){ $ Ids [] = $ _ base_ids [$ _ temp_key [$ x]; } Return $ ids; } |
Example 2
The code is as follows: |
Copy code |
<? Php $ A = array (, 8 ); Echo "$ a original sequence: Foreach ($ a as $ v) Echo $ v. "t "; Shuffle ($ ); Echo "<br/> $ a is in the following order: Foreach ($ a as $ v) Echo $ v. "t "; ?> |
The first result is:
The second result is:
The third result is: