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

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

青灯夜游
Release: 2023-03-11 18:06:01
Original
1659 people have browsed it

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";
}
Copy after login

"=>"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);
Copy after login

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();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template