Differences between Echo () and print (), require (), and include () in PHP _php tutorial

Source: Internet
Author: User
The difference between 1.echo and print

The functions of Echo and print in PHP are basically the same (output), but there are subtle differences between the two. There is no return value after the echo output, but print has a return value and returns Flase when its execution fails. It can therefore be used as a normal function, such as executing the following code after the variable "value will be 1."

$r = print "Hello world";

This means that print can be used in some complex expressions, while Echo is not. However, because the Echo statement does not require any values to be returned, the Echo statement in the code is running more efficiently than the print statement.

the difference between 2.include and require

The features of include () and require () are basically the same (included), but there are some differences in usage, including that include () is a conditional include function, and require () is an unconditional include function. For example, in the following code, if the variable $ A is true, it will contain the file a.php:

if ($a) {
Include ("a.php");
}

and require () is different from include (), no matter what the value of $ A, the following code will include the file a.php into the file:

if ($a) {
Require ("a.php");
}

In the case of error handling, the include statement is used, and if an error occurs, the program skips the include statement, although an error message is displayed but the program will continue to execute! But Requre will give you a fatal mistake.

Of course, we can also understand the literal meaning of seven points: Requre is a very tough request, the meaning of the request.

3.require_once () and include_once () statements

Off-topic, because of the long image, the simple require_once () and include_once () statements correspond to the require () and the Include () statements respectively. The require_once () and include_once () statements are primarily used when you need to include multiple files, and you can effectively avoid errors where the same piece of code is included in a function or variable that is repeatedly defined.

4. The difference between an empty string (' ') and null

PHP hollow strings and null are stored with a value of 0, but they are not the same type, you can try Echo GetType ("), and Echo GetType (NULL), you will find that they print out is a string and null, Of course 0 is also easy to confuse, you can try Echo GetType (0), print the type, you will find that the type of 0 is an integer (integer), the Visible string ("'), null and 0 are" equivalent "but unequal type.

the difference between 5.isset and empty

From the literal meaning we can understand: empty is to determine whether a variable is "empty", and isset is to determine whether a variable has been set. But here's a point to be sure: when a variable value of 0,empty thinks the variable equals null, that's equivalent to no setting. For example, when we detect the $id variable, when $id=0, with empty and isset to detect whether the variable $id is configured, both will return different values: Empty is not Configured, isset can get $id value, see the following example:
$id = 0;
Emptyempty ($id)? print "I am Empty":p rint "I am $id."; Result: I'm empty.
!isset ($id)? print "I am Empty":p rint "I am $id."; /Result: I am 0

the difference between 6.== (ET) and = = = (identity)

Looking back at the difference between the fourth empty string ("") and null, let's look at an example:

' = = NULL;
' = = = NULL;

After running you will find that the first one is true and the second is false! Visible = = is only the comparison value is equal, and = = = Not only compare values, but also compare the type, more stringent.

http://www.bkjia.com/PHPjc/325144.html www.bkjia.com true http://www.bkjia.com/PHPjc/325144.html techarticle the difference between 1.echo and print is basically the same for Echo and print in PHP (output), but there are subtle differences between the two. The echo output has no return value, but print has a return value when its ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.