What is the usage of $ in php

藏色散人
Release: 2023-03-07 07:46:02
Original
5350 people have browsed it

$ is a variable symbol in php. To use it, add the $ symbol to a string to make the string a variable name or object name. Use the syntax such as "class MyClass{private $_val;. ..echo $my->foo();}".

What is the usage of $ in php

Recommendation: "PHP Video Tutorial"

The $ symbol in php is a variable symbol;

Add the $ symbol to a string. This string is a variable name or object name.

In fact, PHP uses the syntax of C language, but there are some differences. The $ symbol plus a string is a variable name or object name.

For example, the following code: (Recommended learning: PHP programming from entry to proficiency)

class MyClass{
private $_val;
 
public function foo(){
return $this->_val;
}
 
public function foo1(){
return $this->_val;
}
......
}
$my = new MyClass;
echo $my->foo();
Copy after login

MyClass is a class name, no $ sign is needed; $_val is a private variable, usually $ It is composed of an underscore and a string; foo and foo1 are two member functions, so there is no need to add the $ sign; $my is an object, and the $ sign must be added.

The above is the detailed content of What is the usage of $ in php. For more information, please follow other related articles on the PHP Chinese website!

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