Double Arrow

The double arrow is the PHP token =>. It is an arrow, and the equal sign as body of the arrow gives it its name of double arrow.

The double arrow is used in several situations:

  • With arrow functions: fn($a) => $a + 1;

  • In arrays, to distinguish the key from the value: ['a' => 3]

  • In list, to distinguish the key from the value: ['a' => $b] = ['a' => 4]

  • In yield, to distinguish the key from the value: yield 'a' => $b;

  • In property hooks, to start the body of the hook: private $p { get => $this->p; }

=> has no relationship with <=, which is a comparison operator, nor with ->, which is the object operator.

<?php

    $array = ['a' => 3, 3];

?>

See also List of Parser Tokens and Understanding the Difference between -> and => in PHP and Laravel.

Related : Arrow Functions, List, Yield, Property Hook, Comparison, Object Operator ->