How to get a list of random arrays via php

不言
Release: 2023-04-01 16:32:02
Original
2967 people have browsed it

This article mainly introduces the method of obtaining a random array list in PHP. It involves the application of random numbers to the traversal of the array. It is of great practical value. Friends in need can refer to it.

The example of this article tells the story of obtaining a random array in PHP. The example program of random array in array is shared with everyone for your reference. The specific implementation method is as follows:

Needless to say, just paste the code directly. array_rand in php is very abnormal, breaking through the understanding of normal people, and is very cumbersome
Example 1:

function create_random_ids( $min,$max,$limited )
{
    $_base_ids = range($min,$max);
    $_temp_key = array_rand ($_base_ids,min(count($_base_ids),$limited+10));
    //拼接
    $ids = array();
    for ($x=0; $x < count($_temp_key); $x++) {
        $ids[] = $_base_ids[$_temp_key[$x]];
    }
    return $ids;
}
Copy after login

Example 2 :

<?php 
$a = array(0,1,2,3,4,5,6,7,8);
echo "$a原来的顺序为:<hr/>";
foreach($a as $v)
 echo $v."t";
shuffle($a);
echo "<br/>$a被打乱后的顺序为:<hr/>";
foreach($a as $v)
 echo $v."t";
?>
Copy after login

The result obtained for the first time is:

The result obtained for the second time is:

The result obtained for the third time is:

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to PHP Chinese website!

Related recommendations:

3 ways to generate random numbers in PHP

About how to find a numerical array in PHP Do not repeat the largest and smallest 10 numbers

About PHP function code for finding polynomial derivatives

The above is the detailed content of How to get a list of random arrays via php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template