In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "the specific application of annotations, variables, arrays, constants and functions in php". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
What is the difference between single quotation marks and double quotation marks in php?
1. As you can see below, the variables in double quotes are parsed and output, while the variables in single quotes are not parsed.
two。 The parsing speed of single quotation marks is faster than that of double quotes.
3. For single quotation marks, there are only two escapes.
4. Except for the above two escape characters, the other characters are output as is.
5. For double quotation marks, escapable characters include\ t,\ r,\ n, etc.
6. In addition to single quotation marks and double quotation marks used to declare string variables, there is also heredoc mode
Program code:
/ / $age = 22
/ / $str1 ='he is $age this year'; / /''output as is
/ / $str2 = "he is $age this year"; / / "to parse the variables in it, output 22
/ / echo $str1, "", $str2
Comments in php
(1) start with / /.
(2) start with #.
# this is shell single-line comment style
(3) there is a multiline comment that begins with / * and ends with * /.
Considerations in php
one。 In js, if a statement has a single line, it can be left unsigned at the end of the line.
two。 However, in php plus, each line must be followed by a semicolon
Although there is an exception in the last sentence of the entire php, it is strongly recommended to add
Three. For pure php pages,? > is optional.
Moreover, for files that are not run directly, but are included by other pages, it is often recommended not to add them? >
In this way, the included pages are faster and faster.
Variables in php
1. There are 8 php variables.
two。 Integer, floating point, Boolean, string, null, array, object, resource
3. In js, declare the variable with the var variable name [= value], declare the variable in php, and directly declare the variable name = value
4. Variable naming convention in php
5. The name of a variable consists of "letters", underscores, numbers, and combinations. And the number can't start.
6. In php, the variable is preceded by a'$'tag
7. Echo is not a function, but a grammatical structure.
8. Variables can be printed out.
9. When you want to print multiple variables, separate them with','
10. The value of a variable
11. Reference transfer and assignment transfer
15. String type
Variables and constants
(1) constant
Variables can be reassigned at any time
/ / $age = 22
/ / $age = 23
/ / echo "", $age
(2) what is the difference between variables and constants?
1. They are declared in different ways.
two。 Once a constant is declared, its value cannot be changed.
Define ('PI',3.14)
PI = 3.23; syntax error
Echo "", PI
3. Variables can be destroyed, and constants cannot be destroyed once they are idealistic.
Unset ($age)
Var_dump ($age)
4. Constants cannot be logged out
Unset (PI); / / syntax error, logout is not allowed
Echo PI
5. Variables have their scope, and external variables cannot be accessed by default within the function.
And constants, once defined, are defined either globally or internally.
It can be accessed anywhere on the page.
(3) naming conventions for variables and constants
1. The naming convention for constants is the same as variables from a grammatical point of view.
Allowed is a combination of letters, numbers, underscores, and numbers cannot begin
two。 From a customary point of view: general constants use "uppercase"
/ / define ('SF',342)
/ / echo SF; / / the latest version has case-sensitive constant names
(4) what are the allowable values of constants?
1. Only scalar type (unitary type) can be assigned to constant.
two。 You cannot assign compound objects, such as arrays, to a constant.
3. Resource-based if assigned to constants, such as leading to some unpredictable errors.
The code is as follows:
The copy code is as follows:
1 define ('AGE',22)
2 define ('HEI',343.234)
3 define ('ROOT','D:/www')
4 define ('LOCK',true)
5 define ('NON',NULL)
6 echo AGE,HEI,ROOT
7 var_dump (LOCK)
8 var_dump (NON)
Control structure in php
(1) any program is inseparable from variables, expressions, and control structures.
(2) in php, else if can be written successively, but it is not allowed in js. We recommend that the specification be written separately, that is, esle if.
(3) in php, the scope of a variable does not look out along the scope as js does.
(4) in php, there is a special class of variables called super global variables. Whether yours is in the function or inside the class, no matter how deep the code is wrapped
Can access the variable.
Php array and js array
(1) two methods of creating arrays in js
(2) in js, the index of the array always increases one by one from 0, and there is no gap in the middle.
1. Var arr=new Array (1, 2, 3, 4)
2. Var arr= [1,2,3]
(3) create an array in php
1. But in php, the index of the array is very flexible
two。 It can be a number or a string.
3. It can even be a mixture of numbers and strings.
4. If the index section specifies a numeric index
5. There is another unit that does not specify an index.
6. Then take the largest numerical index value that has ever appeared in the unit before and then + 1 as its key value.
Php creates the array as follows:
The copy code is as follows:
$arr=array (1, 2, 3)
Print_r ($arr)
/ / =
Arr=array (10 = > 'Zhao', 'adfdssd'= >' Qian', 'Sun', 'name'= >' Zhang Sanfeng')
Print_r ($arr)
7. In php, how to reference the cell value of an array depends on the index.
8. And the index is a digital index.
/ / echo $arr [10]
9. If it is a string index, you must ask for single quotation marks. If you do not add single quotation marks, it will first deal with it as a constant.
/ / define ('name','adfdssd')
/ / echo $arr [name]
(IV) associative array and indexed array
1. The index can be either a pure number, a string, or a mixture of string and number
two。 If the index is a pure number, it is called an indexed array.
3. Otherwise, it's called "associative array."
(5) the differences between the functions in php and those in js
1. In js, you can declare a function with the same name multiple times
two。 But in a php page, you cannot use a function with the same name multiple times
3. In js, function names are case sensitive
4. In php, function names are not case-sensitive (nor are class methods)
5. In php, the number of parameters when calling a function must be the same as that of the declared function
6. In php's function, when a function is declared, a parameter can have a "default value"
The code display of all the above knowledge points
The copy code is as follows:
That's all for the specific application of comments, variables, arrays, constants and functions in php. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.