This article will introduce some common php instance programs used to obtain random arrays in arrays. I hope this method will be helpful to all of you. Paste a piece of code to get a random array in php. no
This article will introduce some common php instance programs used to obtain random arrays in arrays. I hope this method will be helpful to all of you.
Paste a piece of code and get a random array in php. don't talk about it. paste the code directly. the array_rand in php is abnormal, breaking through the understanding of normal people and being tedious.
Example 1 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 code:
- $ A = array (, 8 );
- The original order of echo "$ a is: ";
- Foreach ($ a as $ v)
- Echo $ v. "t ";
- Shuffle ($ );
- Echo"
$ A is in the following order: ";
- Foreach ($ a as $ v)
- Echo $ v. "t ";
- ?>