這裏是什麼,我認爲你所要求的。
<?php
// Create an array and push on the names
// of your closest family and friends
$closefriends = array() ;
array_push($closefriends,"Cessie","Lulu","Tutur");
// Sort the list
sort($closefriends);
// Randomly select a winner!
$rand_friend = array_rand($closefriends, 1);
// Print the winner's name in ALL CAPS
$str = strtoupper($closefriends[$rand_friend]);
echo $str;
?>
在代碼的開始要創建一個數組來你存儲值,例如:「Cessie」,「路路」,「tutur」。
實施例:$YourarrayName = array();
那麼你有array_push()治療陣列作爲一個堆棧,並且推動傳遞的變量到array.This的端部也增加了陣列的長度。
實施例:array_push('the array you want to add to', the values you wanted added, "value", "value")
排序陣列,這是通過排序()函數來完成。這個函數對一個數組進行排序,當這個函數完成時,元素將從最低排列到最高排列。
例sort('name_of_array_to_be_sorted');
要隨機地從使用排序後的數組中選擇和元件的array_rand()功能。本拾取一個或多個隨機條目出的陣列的,並返回鍵(或多個密鑰)的隨機條目。那麼您只需將隨機挑選的值分配給一個變量。
例子:$yourVariable = array_rand('YourArrayName', 'the number of random items you want');
然後這一切的最後一部分,你被要求打印贏家全部大寫字母。這只是strtoupper()函數的一個簡單傳遞。真的,它所做的只是返回一個字符串,並將所有字母字符都轉換爲大寫字母。
然後您只需使用echo聲明來輸出最終值。
你想整理一下這個代碼asmple還是看起來像這樣 – RiggsFolly
這裏輸入代碼是什麼? – arkascha
將您的代碼與本教程中的示例代碼進行比較。 **他們不會匹配** – RiggsFolly