PHP is a computer programming language that is mainly used to develop Web applications (website construction, etc.). In this series of blogs, we introduce the basic knowledge of PHP from the basic syntax of PHP. Make readers learn the fun of programming in a simple way.

This series of blog posts will cover the following nine topics: variables, constants, data types, operators, arrays, flow control (order, selection, loop), functions, file handling, and object orientation

Each article will leave a homework at the end of the article, the answer to get please private chat me, we can actively discuss in the comment section, progress together

The concept of variables

First of all, what are the variables?

If you remember, when you were learning math in high school, you defined algebra. Algebra is arithmetic operations performed with expressions containing characters (variables), each of which is a polynomial with coefficients, such as x+y.

In PHP, we can think of variables as containers for storing data. Please take a look at an example:

$a = 1; /** * Created by ($a = 1); $b = 2; echo $a + $b; 3 / / output

In plain English, defining a variable is like taking an empty bowl with a specific name and dropping the data into the bowl. When retrieving data, you can simply call the bowl by name to retrieve the specific data.

How do I declare a variable

In PHP, you use the $sign to declare a variable. Is not very elegant ~

Declaring a variable must be accompanied by an assignment, otherwise an error will be reported.

$a = 1; /** * Created by ($a = 1); $a = 1; $b = 2; $a = 2; $b = $b; $b = $b; $b = $b

Principle of variables

  • $a = 1;
  • As shown in the previous code, when the code reaches this point, it is opening up a memory space and setting$aPoint to this memory space
  • And then the constant1Deposit in
  • Finally using$aI can represent the constant 1

As shown in the figure:

Naming rules

The naming of variables is not random and needs to have certain rules

  • Variable names can only contain: a-z, a-z, 0-9, and underscore _
  • Variables are not allowed to have any whitespace or punctuation marks other than underscore _
  • The first character after the dollar sign $must not be a number. For example, **$123ABC variable name is incorrect **.

The code field

<? PHP /** * Created by */ ** Created by */ ** Created by */ ** Created by */ // lengyue $age = 2; $age = "China "; $age =" China "; China $_name = $name; $_age = $age; $_age = $age; $NAME = $NAME; $NAME = $age; $AGE = $AGE; $AGE = $AGE; $1name = "ABC "; $1name =" ABC "; $@name = "ABC "; $@name =" ABC "; $%name = "ABC "; $%name =" ABC "; // Syntax error. Cannot start with special symbol

Practice after class

  1. What are PHP variables? What are the naming rules for variables?
  2. Which of the following PHP variable names is wrong?

Practice your answers after class and do a WeChat search.
The senior of the”Reply
phpTo obtain


The article continues to be updated on GitHub
https://github.com/lengyueit/phpFamilyThis has been included. Welcome STAR.

If this post is helpful to you, please give Lengyue a like or add a follow!