This article mainly shares with you the basic knowledge of PHP learning. The content is very simple. I hope it will be helpful to friends who are just starting to learn PHP.
I have been studying PHP for more than a year, and I have accumulated a lot of notes, which are also quite complicated. Let me write an article to sort them out.
php basic part
##PHP<span style="font-family:新宋体"></span> Basic instructions for outputting text:echo<span style="font-family:新宋体"></span> and print<span style="font-family:新宋体"></span>.
The difference between echo and print
echo<span style="font-family:新宋体"></span> is a PHP statement, print<span style="font-family:新宋体"> </span> and print_r<span style="font-family:新宋体"></span> are functions. Statements have no return value. Functions can have return values (even if they are useless)
echo<span style="font-family:新宋体"></span> Output one or more strings. print<span style="font-family:新宋体"></span> can only print out the value of simple type variables (such as int, string) print_r<span style="font-family:新宋体"></span> can print out Values of complex type variables (such as arrays, objects)
The difference between var_dump and print_r
var_dump<span style="font-family:新宋体"></span>Returns the type and value of the expression, while print_r<span style="font-family:新宋体"></span>Only returns the result, which is easier to read than using var_dump<span style="font-family:新宋体"></span> for debugging code.
Variables
Variables are used to store values, such as numbers, text strings, or arrays. All variables in PHP start with a $ symbol.
Global<span style="font-family:新宋体"></span> scope, which can only be outside the function for a visit.
Variables declared inside a function have
LOCAL<span style="font-family:新宋体"></span> scope and can only be accessed inside the function.
global<span style="font-family:新宋体"></span> keyword is used to access global variables within a function.
PHP static keyword
Normally, all variables are deleted when the function completes/executes. However, sometimes I need to not delete a local variable. Achieving this will require further work. To accomplish this, use the static keyword when you first declare the variable:
array[key]<span style="max-width:90%"></span> syntax. Note: This does not mean always quoting key names. There is no need to put quotes around the key names of constants or variables, otherwise PHP<span style="font-family:新宋体"></span> will not be able to parse them.
1. Variable assignments must maintain equal spacing and arrangement
2. No extra spaces are allowed at the end of each line
3. Make sure that the file naming and calling case are consistent. Unix-like systems are case-sensitive
4. Method names are only allowed to consist of letters, underscores are not allowed, the first letter must be lowercase, and the first letter of each subsequent word must be capitalized
5. Attribute names are only allowed to consist of letters, underscores are not allowed⋯⋯
6. For access to object members, we must always use the "get" and "set" methods
7. When a class member method is declared as private, it must start with a double underscore; when it is declared as protected, it must start with a single underscore "_"; member attributes declared as public are not allowed to contain Underline.
8. If we need to define some frequently used methods as global functions, they should be defined in the class in static form
9. Use lowercase letters for function names and underscores should be able to clearly describe the function of the function.
10.Boolean values and null values are both lowercase.
11. When a string is composed of plain text (that is, it does not contain variables), single quotes (') must always be used as the delimiter
12. Use the array type When declaring an associative array, it should be divided into multiple lines to ensure that the keys and values of each line are aligned
13. All code in the class must be indented with four spaces
14 . It is not allowed to use var to declare variables. Class member variables must be declared as private, protected and public. Usually get and set methods are used to access class members.
15. Methods must always use private, protected or public to declare their scope
16. No extra spaces are allowed between the function or method name and the parameter brackets
The above is the detailed content of Summary of basic knowledge of php learning. For more information, please follow other related articles on the PHP Chinese 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