Vincent1989
Vincent1989

Reputation: 1657

Referencing return function?

I'm returning a simple function with two variables,

function checkerValidate(){
$emptyOrNot = "";
$validOrNot = "";

    if(!empty($_POST['domain']))
    {//not empty
        $emptyOrNot = "notEmptyUrl";            
        if (filter_var($url, FILTER_VALIDATE_URL) === TRUE) {
            $validOrNot = "validUrl";
        }else{
            $validOrNot = "notValidUrl";
        }
    }else
    {//empty
        $emptyOrNot = "emptyUrl";
    }
    return array($emptyOrNot, $validOrNot);

}

To reference the two variables outside the function I use:

<?php echo checkerValidate()[0]; ?> 
<?php echo checkerValidate()[1]; ?> 

I tried and upload to the server and it was working, however the I'm using Dreamweaver IDE and it states that checkerValidate()[0] and checkerValidate()[1] are not valid.

Can anyone clarify on this?

Upvotes: 2

Views: 35

Answers (1)

Antony D&#39;Andrea
Antony D&#39;Andrea

Reputation: 1004

That syntax is valid from PHP 5.4. There is a possibility that your IDE is set to syntax check a lower version of PHP which is why it thinks it is wrong.

Your server obviously has a version of PHP greater than or equal to 5.4 so it works just fine (you can check using php -v).

Upvotes: 1

Related Questions