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!
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
PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals.
This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati
CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu
Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems.
With a large collection of extensions for many programming languages, VS Code can be c
This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an
CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase.
What is a vowel?
Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase:
a, e, i, o, u
Example 1
Input: String = "Tutorialspoint"
Output: 6
explain
The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total
JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,