This article mainly introduces the usage of the this keyword in php, and analyzes the principles and usage skills of internal variables and methods of this keyword using specific examples, if you need this keyword, refer to the example in this article to describe the usage of this keyword in php. We will share this with you for your reference. The details are as follows:
The following defines a Cart class
Items [$ artnr] + = $ num;} // retrieves $ num from the car. function remove_item ($ artnr, $ num) {if ($ this-> items [$ artnr]> $ num) {$ this-> items [$ artnr]-= $ num; return true ;} else {return false ;}}}?>
You can use a piece of code to describe the problem. within the definition of a class, you cannot know which name objects are accessible: When writing a Cart class, the object name will be named $ cart or $ another_cart. Therefore, you cannot use $ cart-> items in the class. However, you can use the pseudo variable $ this to access your own functions and variables within the class definition. $ This variable can be understood as "my own" or "current object ". Therefore, '$ this-> items [$ artnr] + = $ num' can be interpreted as "adding $ num to the $ artnr counter of my own item array" or "in the current object's the $ artnr counter of the item array plus $ num ".
The above is the content of this keyword usage analysis in php. For more articles, please follow the PHP Chinese website (www.php1.cn )!