2013-08-26 36 views
-2

嗨Dreamweaver說在下面一行有語法錯誤。這樣對嗎?語法錯誤 - PHP

if (!in_array(array_reverse(explode(".",strtolower($file['name'])))[0],$allowedExtensions)) 
+0

是什麼錯誤只從語法錯誤說分開? – Markasoftware

+0

您是否嘗試運行腳本?你得到了什麼錯誤? – mithunsatheesh

+0

永遠不要說「我得到了一個錯誤」。說「我得到了這個錯誤」,然後**將整個錯誤逐字粘貼到您的問題**中,因爲我們無法讀懂您的想法。 –

回答

3

正在使用的PHP版本不支持索引函數的返回值。升級到更新的版本,或將其變爲單獨的語句。

0

它可能不解析爲PHP 5.4,這是需要了解function()[0]語法。

而且你parameted爲in_array()是不正確的

布爾in_array(混合$針,數組$草垛[,布爾$嚴格= FALSE])

0

Dreamweaver的是罪魁禍首

你的代碼很好。我試過你的代碼,它工作正常。 既然你沒有透露我們的變數。 $file$allowedExtensions。我認爲這是你必須做的。

另外,if迴路是就好了

得到像PHPStorm一個新的編輯器的Eclipse PHP


<?php 
$file=array('name'=>'test.gif'); 
$allowedExtensions=array('.gif','.jpg','.png'); 
if (!in_array(array_reverse(explode(".",strtolower($file['name'])))[0],$allowedExtensions)) 
{ 
    echo "Valid File Extension"; 
} 
else 
{ 
    echo "Invalid File Extension"; 
}