<?php
class getValues {
function __construct($inputArray){
$this->inputArray = $inputArray;
}
//該函數此處沒用到
public function inputValue($inputArray) {
$this->inputArray = $inputArray;
}
public function getValue($number) {
$this->number = $number;
for($i = 0; $i < $this->number; $i ++) {
$count = count ( $this->inputArray ) - 1 - $i;
$index = rand ( 0, $count);
$getArray [$i] = $this->inputArray [$index];
$temp = $this->inputArray [$count];
$this->inputArray [$count] = $this->inputArray [$index];
$this->inputArray [$index] = $temp;
}
//asort ( $getArray ); // 從小到大排序,根據需要修改
return $getArray;
}
}
//測試代碼
$keywords = array(
"我們",
"你們",
"他們"
);
$getValue=new getValues($keywords);
$key = $getValue->getValue(1);//從數組中隨機抽取一個元素
?>
推薦一個自己業余時間開發的網盤搜索引擎,360盤搜(www.360panso.com)