Copy code The 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",
"them"
);
$getValue=new getValues();
$getValue->inputValue( $keywords);
$key = $getValue->getValue(1); // Randomly extract an element from the array
echo $key;
? >
http://www.bkjia.com/PHPjc/326147.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326147.htmlTechArticleCopy the code as follows: ?php class getValues { public function inputValue($inputArray) { $this-inputArray = $ inputArray; } public function getValue($number) { $this-number = $nu...