开发者

PHP array syntax/operator?

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 th开发者_StackOverflow中文版e written function in C before compiled, or If I just have no idea what I am talking about :)


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜