0

I have an error in this opencart 1.5.6.4 script

"Parse error: syntax error, unexpected '[', expecting ')' "

the script is like this:

 'title' => explode('-', $this->config->get('rumahkaosbintang_city'))[0] . ' - ' . $tujuan[0]. ' (' . $weight / 1000 . ' Kgram)' ,

could you tell me what is wrong with it?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Faiz
  • 117
  • 1
  • 10

1 Answers1

0

PHP can directly access an element from a function returned array (like explode('-', value)[0]) only since version 5.4.

Please check your PHP version, and upgrade it if it's lower, or otherwise use different syntax.
For example, to get the Nth element of a function returned array, before 5.4 you could do:

$NthArrayElement = array_slice(returningArrayFunction(), N - 1, 1);

And, in your use case:

$firstArrayElement = array_slice($this->config->get('rumahkaosbintang_city'), 0, 1);
$title => explode('-', $firstArrayElement . ' - ' . $tujuan[0]. ' (' . $weight / 1000 . ' Kgram)' ,
MarcoS
  • 17,323
  • 24
  • 96
  • 174