In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "the difference between echo and print in php and what are the data types". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn the difference between echo and print in php and what are the data types.
Basic part of php
The basic instructions for PHP output text: echo and print.
The difference between echo and print
Echo is a PHP statement, print and print_r are functions, a statement does not return a value, and a function can have a return value (even if it is not useful)
Echo outputs one or more strings.
Print can only print the value of a simple type variable (such as int,string)
Print_r can print out the values of complex type variables (such as arrays, objects)
The difference between var_dump and print_r
Var_dump returns the type and value of the expression, while print_r returns only the results, which is easier to read than debugging code using var_dump.
Variable
Variables are used to store values, such as numbers, text strings, or arrays. All variables in PHP start with the $symbol.
PHP variable names are case sensitive!
PHP has three different variable scopes:
Local (local)
Global (global)
Static (static)
Variables declared outside the function have Global scope and can only be accessed outside the function.
Variables declared inside the function have LOCAL scope and can only be accessed within the function.
The global keyword is used to access global variables within a function.
PHP static keyword
Typically, when the function completes / executes, all variables are deleted. However, sometimes I need not to delete a local variable. Further work is needed to achieve this.
To do this, use the static keyword when you first declare a variable:
Php Typ
Php type: * * PHP supports eight primitive types. **
Boolean type
To specify a Boolean value, use the keyword TRUE or FALSE. Both are case-insensitive.
Integer type
We can use (int) to cast decimal types to integers.
Array
There are three kinds of arrays in php:
Indexed array: that is, the subscript is a sequential integer as an index (for example, row and column) $class [5]
Associative array: that is, the subscript is a string as an index (such as a name) $class2 ["zhangsan"]
Multidimensional array-an array containing one or more arrays
The subscript is either an integer or a string.
Array units can be accessed through the array [key] syntax.
Note: that doesn't mean that key names are always in quotation marks. There is no need to quote keys with constant or variable names, otherwise PHP will not be able to parse them.
Array operator
Example name result $a + $b union of $an and $b $a = = $b is equal if $an and $b have the same key / value pair, then it is TRUE$a = = $b congruent if $an and $b have the same key / value pair and the order and type are the same, then it is TRUE$a! = $b is TRUE$a $b if $an is not equal to $b, then it is TRUE$a! = $b is not equal if $an is not equal to $b, then it is TRUE.
The + operator appends the array element on the right to the array on the left, and if there are key names in both arrays, only the one on the left is used, and the one on the right is ignored.
Object
To initialize an object, use the new statement to instance the object into a variable.
Common function
The strlen () function is used to calculate the length of a string.
The strpos () function is used to retrieve a string or a character within a string.
Constant
You can use the define () function to define constants. Once a constant is defined, it can no longer be changed or undefined.
Commonly used magic constants:
Define a constant example:
Php string operator
In PHP, there is only one string operator.
Collocation operator (.) Used to connect two string values. For example, echo "a =". $a. "
"
On the left, concatenate the string word "a =" with the value of the variable $a, and the second with the newline character.
"Connect
Php function
A function is executed only when it is called, just like js, and the function definition begins with the function keyword.
When there is no return statement, the above will become "- 2percent 10 ="
Process control
Here, I will only talk about the foreach statement.
The foreach statement traverses the output array:
Syntax:
Foreach (array_expression as $value) {statement}; foreach (array_expression as $key = > $value) {statement}
The parameter array_expression is the specified array to traverse, and $value is the value of the array
The above code will output:
Name:Marry
Name:Lorry
Name:mike
Two important magic tricks
1. _ _ set () method: this method is used to set a value for a private member property. There are two parameters, the first parameter is the name of the property you want to set the value for, and the second parameter is the value to be set for the property, with no return value. 2. _ _ get () method: this method is used to obtain the property value of a private member. There is a parameter that passes in the name of the member property you want to obtain and returns the obtained property value. This method does not need to be called manually.
Methods in php are not case sensitive
Require (dirname (_ _ FILE__).'/ global.php'); / / introduce the global file require (dirname (_ _ FILE__).'/ config.ini.php'); / / introduce the basic configuration file
Object operator and double colon operator
In the member methods of a class, you can access non-static properties by using-> (object operator): $this- > property (where property is the property name).
Static properties are accessed with:: (double colon): self::$property.
= > and->
= > array member access symbol,-> object member access symbol
$this- > $name=$value: set the value of the name variable of the current class to $value
This represents the class itself, and-> is the operator that accesses the members of its class
Double colon operator (::) class name:: static property / method
"::" is used to call static properties and methods in the class
Include (): contains external files with syntax format include (string filename)
Require (): will output an error message and terminate the script
Include_once (): when the same file is called multiple times, the program will only call it once
Require_once (): first check whether the file has been called somewhere else
Array_pop (): gets and returns the last element in the array
Count (): count the number of elements in the array
Array_search (): gets the key name of the element in the array
$array_keys (): gets all the key names of the repeating elements in the array
Single and double quotation marks
PHP treats the data in single quotes as a normal string and no longer processes it. And the double quotation marks have to deal with the string in it.
Get and post
$_ GET [] and $_ POST [] global arrays: used to receive data passed to the current page by the GET and POST methods, respectively. "[]" contains name.
There are three common methods for passing php parameters: $_ POST [], $_ GET [], and $_ SESSION [], which are used to get the values of the form, URL, and Session variables, respectively.
The differences between get and post in form submission are summarized as follows:
GET is to get data from the server, and POST is to transfer data to the server.
GET adds the parameter data queue to the URL referred to in the ACTION attribute of the submitted form, and the value corresponds to each field in the form, which can be seen in URL. Through the HTTP POST mechanism, POST transmits each field in the form together with its contents in the HTML HEADER to the URL address referred to by the ACTION attribute. The process is not visible to the user.
For GET mode, the server uses Request.QueryString to obtain the value of the variable, and for POST mode, the server uses Request.Form to obtain the submitted data.
The amount of data transmitted by GET is small and cannot be greater than 2KB (this is mainly due to the length limit of URL). POST transmits a large amount of data and is generally regarded as unrestricted by default. But in theory, the limit depends on the processing power of the server.
The security of GET is lower than that of POST. Because of the GET transmission process, the data is placed in the requested URL, and now many existing servers, proxy servers or user agents will record the request URL in the log file and put it somewhere, so that some private information may be seen by third parties. In addition, the user can also see the submitted data directly in the browser, and some internal messages will be displayed in front of the user. All operations of POST are invisible to the user.
When FORM submits, if Method is not specified, it defaults to GET request (. Net defaults to POST), and the data submitted in Form will be appended to url. Separate from url. Alphanumeric characters are sent as is, but spaces are converted to "+" signs and other symbols are converted to% XX, where XX is the ASCII (or ISO Latin-1) value of the symbol in hexadecimal. The data submitted by the GET request is placed in the HTTP request protocol header, while the data submitted by POST is placed in the physical data; the data submitted by GET can only have a maximum of 2048 bytes, while POST does not have this limit. The parameters passed by POST are in doc, that is, the text passed by http protocol. When accepted, the parameters are parsed. Get the parameters. It is generally better to use POST. The data submitted by POST is implicit, GET is passed in url to pass some data that does not need to be kept secret, GET is by passing parameters in URL, POST is not.
The data requested by 1.GET will be appended to the URL (that is, the data will be placed in the HTTP protocol header). Split the URL and transmit data, and the parameters are connected by &
The data submitted by 2.GET can only be 1024 bytes at most. In theory, POST has no limit and can transmit a large amount of data. The maximum is 80KB in IIS4 and 100KB in IIS5.
HTTP status code
The difference between cookie and session
The content of cookie mainly includes: name, value, expiration time, path and domain. Together with the domain, the path forms the scope of cookie. If the expiration time is not set, it means that the
The lifetime of cookie is during the browser session. When you close the browser window, the cookie disappears. A cookie whose lifetime is a browser session is called a session cookie.
Session cookie is generally not stored on the hard disk but in memory, of course, this behavior is not specified by the specification. If the expiration time is set, the browser will set the cookie
Save to the hard drive, close and open the browser again, and the cookie will remain valid until the set expiration time is exceeded.
When a program needs to create a session for a client's request, the server first checks whether the client's request contains a session identity.
(called session id). If it is included, the session has been created for this client before, and the server retrieves the session according to session id.
Use (if it cannot be retrieved, a new one will be created), if the client request does not contain a session id, create a session for this client and generate a phase with this session
The value of the associated session id,session id should be a string that is neither repetitive nor easy to find rules to copy. This session id will be used in this response
Is returned to the client for saving. The session id can be saved using cookie, so that during the interaction, the browser can automatically send the logo to the
Server.
1. Cookie data is stored in the client's browser, and session data is stored on the server.
2. Cookie is not very secure. Others can analyze the local COOKIE and cheat on COOKIE.
Session should be used for security reasons.
3. Session will be saved on the server for a certain period of time. When the number of visits increases, it will consume the performance of your server.
To reduce server performance, you should use COOKIE.
4. The data saved in a single cookie cannot exceed 4K, and many browsers limit a site to 20 cookie.
5. So personal suggestions:
Store important information such as login information as SESSION
If you need to keep other information, you can put it in COOKIE.
Php code specification
1. Variable assignments must be equally spaced and arranged
two。 No extra spaces are allowed at the end of each line
3. Make sure that the naming of the file is consistent with the case of the call, because the Unix-like system is case-sensitive
4. Method names are only allowed to consist of letters, underscores are not allowed, the first letter should be lowercase, and the first letter of each word should be capitalized after that.
5. Attribute naming is only allowed to consist of letters, and underscores are not allowed in ⋯⋯.
6. For access to object members, we must always use "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 properties declared as public are not allowed to contain an underscore at any time.
8. If we need to define some frequently used methods as global functions, we should define them in the class as static.
9. The naming of the function uses lowercase and underscore and should be able to clearly describe the function of the function.
10.Boolean and null values are lowercase.
11. When a string is made up of plain text (that is, it does not contain variables), it must always use single quotes (') as the delimiter
twelve。 When you declare an associative array using the array type, you should divide it into multiple rows to ensure that the keys of each row are aligned with the value
13. All code in the class must be indented with four spaces
14. Var is not allowed to declare variables, class member variables must be declared as private,protected and public. Get and set methods are typically used to access class members.
15. A method must always declare its scope with private,protected or public
16. No extra spaces are allowed between the function or method name and parameter parentheses
At this point, I believe you have a deeper understanding of "the difference between echo and print in php and what are the data types?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.