Copy CodeThe code is as follows:
Class GetValues {
Public Function Inputvalue ($inputArray) {
$this->inputarray = $inputArray;
}
Public Function GetValue ($number) {
$this->number = $number;
for ($i = 0; $i < $this->number; $i + +) {
$index = rand (0, COUNT ($this->inputarray)-1-$i);
$getArray [$i] = $this->inputarray [$index];
unset ($this->inputarray [$index]);
for ($k = $index; $k < count ($this->inputarray)-1; $k + +) {
$this->inputarray [$k] = $this->inputarray [$k + 1];
}
}
Asort ($getArray); Sort from small to large, modify as needed
return $getArray;
}
}
Test code
$keywords = Array (
"We",
"You,"
They
);
$getValue =new getValues ();
$getValue->inputvalue ($keywords);
$key = $getValue->getvalue (1);//randomly extracting an element from an array
Echo $key;
? >
http://www.bkjia.com/PHPjc/326147.html www.bkjia.com true http://www.bkjia.com/PHPjc/326147.html techarticle Copy the code as follows: PHP class GetValues {public Function Inputvalue ($inputArray) {$this-inputarray = $inputArray;} public F Unction GetValue ($number) {$this-number = $nu ...