2

I have a function that receives parameters as an array:

public myFunction($options = array("option1"=>true, "option2"=>true, "option4"=>"astring"), $anotherparameter = 0) {
    if($options["option1"] === true) {
         //And here all the magic is done
    }
}

When I use it somewhere else I use something like this:

myFunction(["option1"=>false], 1) { //Magic }

I have installed PHP 5.5 on my localhost and this WORKS, when I upload it to my remote server it throws an error, and I have to put the array parameters like:

myFunction(array("option1"=>false), 1) { //Magic }

Is it due to PHP version? The remote server has PHP 5.3, I just updated it to 5.4, but I want to know if I need an specific version of PHP to work with this kind of array syntax, or should I use always array(...) format?

1 Answer 1

3

The array short syntax [] was added in PHP 5.4 :)

See: http://php.net/manual/en/migration54.new-features.php

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I will then update my servers to PHP 5.4 now that I know I can use it safely with this version! I just didn't know how to research for that specific subject, so I asked here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.