How can “[” be an operator in the PHP language specification?

前端 未结 3 574
萌比男神i
萌比男神i 2021-02-03 17:31

On the http://php.net/manual/en/language.operators.precedence.php webpage, the second highest precedence level contains a left-associative operator called [.

<
3条回答
  •  伪装坚强ぢ
    2021-02-03 18:33

    In PHP you can initialize empty arrays with [] so in order to know how to define an array the precedence of the next character defines on how to initialize the array.

    Since arrays are part of the syntax structure, it is done before any math, it simply has a higher precedence than other calculative operators for that reason.

    var_dump([5, 6, 7] + [1, 2, 3, 4]); # 5674 - The array's must be known before applying the operator
    

    However in all honesty I don't really understand the question. In most programming languages the [ and the ] are associated with arrays which is part of the base syntax that always have a high priority (if not the highest)

提交回复
热议问题