Php randomly extracts some element code from the array. Php randomly extracts some element code from the array for your reference. The code is as follows: Copy the code? PhpclassgetValues {publicfunctioninputValue ($ inputArray) {$ this-inputArray $ php randomly extracts some element code from the array for your reference.
| 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); // sorts data from small to large and can be modified as needed
Return $ getArray;
}
}
// Test code
$ Keywords = array (
"We ",
"You ",
"They"
);
$ GetValue = new getValues ();
$ GetValue-> inputValue ($ keywords );
$ Key = $ getValue-> getValue (1); // randomly selects an element from the array.
?> |
Bytes. The code is as follows? Php class getValues {public function inputValue ($ inputArray) {$ this-inputArray = $...