The meaning of -> and => symbols in PHP

The meaning of -> and => in PHP

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

When I first encountered these two symbols, I didn't know what they meant, and only after passing through Baidu did I post the secrets of these two symbols.

Let's take a look at the secret in PHP ->, the following code.

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

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 stand for? After going through Baidu, I think it represents the meaning of the word "的" in Chinese characters. For example, this line of code translates to this->speed+=10, this line of code. ->What does it stand for? After passing through Baidu, I think it represents the meaning of the word "的" in Chinese characters. For example, this line of code is translated asthis>speed+=. 1 0 , which line generation of code . >On behalf of the table what it does ? In after over one hundred degrees later , my self has recognized as his generation of table of a Chinese character in " of " this a word of containing meaning , than as this line on behalf of the code , turn translated over to you is this a speed equal to the speed plus 10 . Of course, this only represents my point of view, if there is a mistake, please advise.

The next step is =>. Simply put, the => symbol separates the key and the value. The left side represents the key and the right side represents the value. Let's look at a piece of code.

<?php //From the array variable $arr, read the value of apple with the key $arr = array('apple'=>"apple",'banana'=>"banana",'pineapple'=>"pineapple" ); $arr0=$arr["apple"]; if( isset($arr0)) {print_r($arr0);} ?>

In this code, first declare an arr array, and then declare a key whose arr0 is equal to apple, then use IF to determine whether it exists, and if it exists, output the value on the right side of the key in the array.
To put it simply, it is to give someone a nickname, use the nickname to represent someone, and you can know who he means by mentioning his nickname.

Guess you like

Origin blog.csdn.net/weixin_45557228/article/details/109597006