" is an array operator, used to correspond to the key value and key name in the array. The syntax is "array(key => value)"; "->" is used to refer to the method and key name of the class instance. Attribute, the syntax is "$obj->a"."/> " is an array operator, used to correspond to the key value and key name in the array. The syntax is "array(key => value)"; "->" is used to refer to the method and key name of the class instance. Attribute, the syntax is "$obj->a".">

Home >Backend Development >PHP Problem >What do => and -> mean in php

What do => and -> mean in php

WBOY
WBOYOriginal
2022-02-25 11:15:064043browse

In PHP, "=>" is an array operator, used to correspond to the key value and key name in the array. The syntax is "array(key => value)"; "-> " is used to refer to methods and properties of class instances, and the syntax is "$obj->a".

What do => and -> mean in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

What do => and -> mean in php

1. The meaning of =>,->:

- > is used by objects to execute methods or obtain attributes.

=> is applied to key and value pairs in the array.

2. Usage

1. Usage of => The relationship between the key and value used in the array. For example:

$a = array('0' => '1','2' => '4',);echo $a['0'];echo $a['2'];

2. -> usage classes are used to refer to the methods and attributes of class instances. For example:

class Test{function add(){return $this->var++;}var $var = 0;}$a = new Test; 
//实例化对象名称
echo $a->add();echo $a->var;

Extended information

The -> code in PHP is as follows:

<?php
class Car {
public $speed = 0;
//增加speedUp方法,使speed加10
public function speedUp(){
$this->speed+=10;
} 
}
$car = new Car();
$car->speedUp();
echo $car->speed;
?>

In PHP => The code is as follows:

<?php
//从数组变量$arr中,读取键为apple的值
$arr = array(&#39;apple&#39;=>"苹果",&#39;banana&#39;=>"香蕉",&#39;pineapple&#39;=>"菠萝");
$arr0=$arr["apple"];
if( isset($arr0) ) 
{print_r($arr0);
}
?>

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What do => and -> mean 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