What do -> and => mean in PHP

醉折花枝作酒筹
Release: 2023-03-09 15:50:01
forward
2241 people have browsed it

This article will introduce to you the meaning of "->" and "=>" in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

What do -> and => mean in PHP

While learning PHP, I encountered the two symbols -> and =>.

When I first encountered these two symbols, I didn’t know what they represented. I only discovered the secrets of these two symbols after going through Baidu.

Let’s take a look at the secret of -> in PHP, as shown below.

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

In this, we can see that a speedUp method is defined in the class. In this method, we can see $this->speed =10, this line of code . ->What does it represent?

After going through Baidu, I think it represents the meaning of the word "的" in Chinese characters. For example, this line of code translates to the speed of $this equal to speed plus 10. Of course this only represents my own point of view, please let me know if I am wrong.

The next step is =>. Simply put, it is the => symbol to separate keys and values. The left side represents the key and the right side represents the value. Let’s look at some code.

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

In this code, first declare an arr array, and then declare a key where arr0 is equal to Apple. Then use IF to determine whether it exists. If it exists, output the value on the right side of the key in the array. .

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!

Related labels:
php
source:csdn.net
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!