" operator is a method for operating member variables in a class. It accesses functions or objects in the class as an instantiated object, such as "$runoob->getUrl();"; while "=>" is The operator used when mapping the key and value of an array. The syntax "index=>values" can be used to assign values ​​to keys."/> " operator is a method for operating member variables in a class. It accesses functions or objects in the class as an instantiated object, such as "$runoob->getUrl();"; while "=>" is The operator used when mapping the key and value of an array. The syntax "index=>values" can be used to assign values ​​to keys.">

Home  >  Article  >  Backend Development  >  What is the difference between -> and => operators in php

What is the difference between -> and => operators in php

青灯夜游
青灯夜游Original
2021-07-21 20:01:361588browse

Difference: The "->" operator is a method for operating member variables in a class. It accesses functions or objects in the class as an instantiated object, for example "$runoob->getUrl(); "; and "=>" is the operator used when mapping the key and value of the array. The syntax "index=>values" can assign values ​​to the keys.

What is the difference between -> and => operators in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

##“-> "Operator

This operator is a method to operate member variables in a class, which can be non-static member variables, such as:

 class xxx{
  private $test;
 $this-test="111";
}

"=>"Operator

This operator is used when mapping the key and value of an array.

The syntax "

index => values", separated by commas, defines the index and value.

The difference between -> and => operators in PHP

In PHP, the => operator is usually used for arrays During operation, the general form is as follows:

$arr = array(key=>value,key2=>value2);

Assign a value to the key in the array.

The key can be an integer or a string, and the value can be any type of value.

This operator is easily confused with greater than or equal to (>=), please note.

And->Access functions or objects in the class as instantiated objects, for example:

$runoob->getUrl();

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of What is the difference between -> and => operators in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn