-1

Running this on a localhost, everything ran fine. Now, when running it on a web server, I'm getting parse errors regarding the [] in the first line. Is this not a legitimate way to declare an array in PHP?

function render($template, $values = [])
{
    // if template exists, render it
    if (file_exists("../templates/$template"))
    {
        // extract variables into local scope
        extract($values);
        // render template
        require("../templates/$template");
    }
potashin
  • 44,205
  • 11
  • 83
  • 107
Cardy31
  • 1
  • 1

2 Answers2

1

In PHP 5.4 and later, you can now define an array using []. Everything else about syntax is the same

$var = array('key' => 'val');

PHP 5.4 and later

$var = ['key' => 'var'];
Machavity
  • 30,841
  • 27
  • 92
  • 100
0

The bracket syntax is available starting from PHP 5.4 onwards. Try array() instead of [].

igi33
  • 51
  • 1
  • 2
  • 5