What is the name of => operator in PHP used in arrays?

Asked

Viewed 716 times

15

In PHP, when we declare a array directly, we have the operator =>.

I know that in PHP we have the ->, that is Separator Object, but I had to give the name to => and could not explain.

What is his name?

2 answers

13


To double arrow (=>) the manual serves to assign a value to a specific key in setting a array and also to separate key from a value in a foreach, as cited by Maniero.

For arrays, assigning a value to a named key is performed using the "=>" Operator. The precedence of this Operator is the same as other assignment Operators.

Source: Assignment Operators

On the page of precedences of operators you can see this row, note the last element of the second column.

Associativity |Operators                                       |Additional Information
right         |  = += -= *= **= /= .= %= &= |= ^= <<= >>= =>   |assignment

Regarding the name of the symbol => in the PHP documentation there seems to be no specific name, the closest to formal would be T_DOUBLE_ARROW (as pointed out in the comments), which appears in syntax errors.

Informally it is known as fat comma, term that probably came from Perl language PHP inherited from some characteristics.

  • Does it have to do with this guy T_DOUBLE_ARROW?

  • 1

    Is the very. T_DOUBLE_ARROW is the name by which the parser recognizes this arrow.

  • I had already seen the term fat comma in a book, I’ll look for the reference later.

10

It is not an operator, contrary to popular belief and error in Wikipedia, at least for PHP. The language has those operators. It is only a language construction element that separates the key from the value of arrays associative. We can call it punctual, as is the ;. It is something that is used to give fluidity to the code text.

  • He then left one more open question: So how are these "building elements" termed? Tokens?

  • Token is any element of language construction. I don’t know if I can say that they are synonymous, I think so, but I don’t guarantee. I don’t know if we can call this particular element something more specific than token, which is too generic. Maybe call it the arrays associative. That I have found, there is nothing in the documentation about it. Officially it seems that the language does not give any name. but I would keep the name double arrow is closest to something official. I don’t trust the article without Wikipedia references.

  • I’m still looking for some official reference, the closest I could find was perl documentation from whom php inherited quite a lot. It’s just evidence, nothing official.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.