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 and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.
PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.
PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.
PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.
PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.
PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.
PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.