2016-12-07 20 views
-1

即時通過Codecademy開始學習PHP。 andd我在第7行得到了一個分析錯誤 我在網上查詢它,我嘗試了和沒有引號,它不起作用。 有人可以幫我弄清楚什麼是錯的嗎? 在此先感謝!Codecademy函數,第一部分PHP

<html> 
<p> 
<?php 
// Create an array and push on the names 
// of your closest family and friends 
$closefriends = array ("Cessie","Lulu","Tutur",) ; 
int array_push("Cessie","Lulu","Tutur",) ; 
sort ($closefriends); 
// Sort the list 

// Randomly select a winner! 

// Print the winner's name in ALL CAPS 
?> 
</p> 

+0

你想整理一下這個代碼asmple還是看起來像這樣 – RiggsFolly

+0

這裏輸入代碼是什麼? – arkascha

+0

將您的代碼與本教程中的示例代碼進行比較。 **他們不會匹配** – RiggsFolly

回答

-2
  • 當定義一個數組,不使用逗號的最後一個項目之後。

  • 刪除enter code here INT

  • 刪除array_push,它有語法錯誤,你已經有你的數組中的值

1

這裏是什麼,我認爲你所要求的。

<?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聲明來輸出最終值。

+0

非常感謝您,能否向我解釋有關代碼的更多信息以及如何瞭解有關代碼的更多信息語法,它殺了我。 –

+0

你的意思是PHP全部在一起還是隻是上面的代碼? – whisk

+1

@ Jean-Huguesruby如果這是您正在尋找的答案,請將其標記爲已接受的答案。 – whisk