php arrow operator code example

Example 1: php =>

PHP =>
  //The double arrow operator, => 
  //Used as an access mechanism for arrays.
  //The left side will have a corresponding value on the right side in array. 
  //This can be used to set values into a corresponding index of an array. 
  //The index can be a string or number.
$myArray = array(
    0 => 'Red',
    1 => 'Orange',
    2 => 'Yellow',
    3 => 'Green'
);

Example 2: -> in php

// Create a new instance of MyObject into $obj
$obj = new MyObject();
// Set a property in the $obj object called thisProperty
$obj->thisProperty = 'Fred';
// Call a method of the $obj object named getProperty
$obj->getProperty();

Tags:

Php Example