PHP array syntax/operator?

China☆狼群 提交于 2019-12-24 05:58:42

问题


When writing the syntax for an associative array in PHP we do the following

$a = array('foo' => 'bar');

I am curious of the relationship of the => syntax, or possibly operator. Does this relate to some kind of reference used in the hash table in ZE, or some kind of subsequent right shift or reference used in C? I guess I am just wondering the true underlying purpose of this syntax, how it relates to ZE and/or php extensions used to handle arrays, how it possibly relates to the written function in C before compiled, or If I just have no idea what I am talking about :)


回答1:


The => symbol a.k.a. T_DOUBLE_ARROW is just a parser token like class, || or ::.

See: The list of php parser tokens

It's nothing special apart from that fact that "it looks like an arrow" and it is used for "array stuff".

Of course the exact usage is more complicated than that but "array stuff" is the short inaccurate description that should do it.

It's used to represent key => (points to) value




回答2:


The answer to that is no simpler than "It looks like an arrow". It's not exactly the assignment operator per say because that would mean a variable-like assignment (like for the array itself). This is an array-internals specific assignment operator.

Webdevelopers are cool like that :P



来源:https://stackoverflow.com/questions/6510705/php-array-syntax-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!