1

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
  • It's just the key => value operator. It's used in foreach loops as well when you need the keys as well as the values of the array you're looping on. In Javascript, the equivalent would be var a = {foo: 'bar'}. Commented Jun 28, 2011 at 17:44

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

3 Comments

"The => symbol a.k.a. T_DOUBLE_ARROW is just a parser token like = or ||." This is more of what I was looking for. I guess now I just need to research how associative arrays are stored in hash tables.
@Headspin The word you are looking for when talking about php hash tables usually is zval. In php pretty much everything is a hash table but variables are stored in so called zvals.
thanks. I am actually looking into the daunting task of writing some PHP extensions which is what lead me to this question. While reading up on zvals specifically ha.
4

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

3 Comments

Do you know the relationship to this within the hash table used to 'store' the array?
I don't see any relation, though that definitely doesn't mean there isn't one. But trust me on this, don't use PHP like C. C is beautiful. PHP is hack-patchy-get-the-job-done. What you asked is a classic example of how weird PHP can seem at times.
hehe, we both went with "it looks like an arrow" +1 ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.