Skip to main content

What do you call this: =>

By Kevin Yank

Programming

Share:

Free JavaScript Book!

Write powerful, clean and maintainable JavaScript.

RRP $11.95

As languages go, PHP has more syntactic sugar than some. Esoteric constructs like list(…) are all over the place, making developers’ jobs easier, but tripping up beginners at the same time.

A particularly useful construct is the foreach loop, which provides a quick way to loop through an array (or, as of PHP5, an object):


$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
   $value = $value * 2;
}

With associative arrays, you can get both the key and value of each item in the array with a little of the aforementioned syntactic sugar:


$a = array(
   "one" => 1,
   "two" => 2,
   "three" => 3,
   "seventeen" => 17
);

foreach ($a as $k => $v) {
   echo "$k => $vn";
}

Okay, so if you code PHP regularly I probably haven’t told you anything you don’t already know. But here’s the twist: what do you call the => operator in that last code sample? C’mon — it must have a name, right? As it turns out, no official name is documented in the PHP manual… so what do you call it?

Reportedly it’s called the “double arrow” in the source code to PHP, but that’s only slightly better than “that little arrowey thing.” What do you think it should be called?

Kevin Yank is an accomplished web developer, speaker, trainer and author of Build Your Own Database Driven Website Using PHP & MySQL and Co-Author of Simply JavaScript and Everything You Know About CSS is Wrong! Kevin loves to share his wealth of knowledge and it didn't stop at books, he's also the course instructor to 3 online courses in web development. Currently Kevin is the Director of Front End Engineering at Culture Amp.

New books out now!

Learn how Git works, and how to use it to streamline your workflow!


Google, Netflix and ILM are Python users. Maybe you should too?