The difference between echo () and print (), require () and include () in PHP, and _php techniques

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

The functions of ECHO and print are essentially the same in PHP (output), but there is a slight difference between the two. echo output does not return a value, but print has a return value that returns Flase when its execution fails. So it can be used as a normal function, such as executing the following code, the value of the variable "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 numeric values to be returned, the Echo statement in the code is more efficient to run 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, 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, the file a.php will be included:

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

and require () differs from include (), regardless of $a value, the following code will include the file a.php in the file:

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

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

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

3.require_once () and include_once () statements

The digression, because of the long image, the simple require_once () and the include_once () statements correspond to the require () and include () statements respectively. The require_once () and include_once () statements are primarily used when you want to include multiple files, and you can effectively avoid the error of repeating a function or variable definition by including the same piece of code.

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

The PHP hollow string and null are all stored in value 0, but their type is not the same, you can try Echo GetType ("); and Echo gettype (NULL); you will find that they are printed with string and null respectively, Of course, 0 is also easy to confuse, you can try the Echo GetType (0), print the type, you will find that 0 of the type is Integer (integer), the Visible string ("), null and 0 are" equivalent "but unequal type.

the difference between 5.isset and empty

On the literal sense, we can see that the empty is to judge whether a variable is "empty", while isset is to determine whether a variable has been set. But here's one thing to be absolutely aware of: When a variable value is 0,empty that the variable equals null, that's equivalent to no setting. For example, when we detect $id variables, when $id=0, with empty and isset to detect whether the variable $id has been configured, both will return a different value: empty think that there is no configuration, isset can get the value of $id, see the following example:
$id = 0;
Emptyempty ($id) print "I am Empty":p rint "I am $id"; Result: I was empty.
!isset ($id) print "I am Empty":p rint "I am $id"; /Result: I am 0

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

Review the difference between the fourth empty string ("") above and null, and then look at an example:

' = = NULL;
' = = NULL;

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

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: 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.