语法错误 - PHP [关闭]

Hi Dreamweaver says there is a syntax error on the following line. Is it right?

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

Indexing the return value of a function is not supported in the version of PHP in use. Upgrade to a newer version, or turn it into separate statements.

It is probably not parsing for php 5.4 which is what is required to understand the function()[0] syntax.

Also your parameted for in_array() are incorrect

bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )

Dreamweaver is the CULPRIT !

Your code is just fine. I tried your code and it works fine. Since you haven't disclosed us the variables. $file and $allowedExtensions. I assume this is what you must be doing.

Also, the if loop is just fine.

Get a new editor like PHPStorm or Eclipse for 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";
}