F
F
fenric2014-04-11 12:21:15
PHP
fenric, 2014-04-11 12:21:15

PHP5, how to access an array without a variable?

Fragment from ORM:

->order('a.' . ['price' => 'price', 'name' => 'name', 'date' => 'id'][$options['sort']])->$options['sort_mode']()

Question:
Why does the construction work on one server, but on the second server the error handler gives the following:
Fatality: syntax error, unexpected '['
1. server: win, apache2, php
2. server: nginx, php-fpm
The php versions are almost the same.. Or ,
perhaps, such a seemingly elementary operation is wrong in itself?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
apasen, 2014-04-11
@fenric

It's about PHP versions, read the description of releases.

B
bzz, 2014-04-11
@bzz

The php versions are almost the same...

Short array notation
['price' => 'price', 'name' => 'name', 'date' => 'id']
appeared in version 5.4, if version < 5.4 use
array('price' => 'price', 'name' => 'name', 'date' => 'id')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question