The difference between echo (), print (), Print_r () in PHP _php tutorial

Source: Internet
Author: User
The difference between Echo and print is that echo can output multiple variable values, while print has only one variable as a string output. The other difference is that ECHO has no return value, and print has a return value of 1.print and cannot output arrays and objects.


Print_r can output stirng, int, float, array, object, etc., the output array will be represented by the structure, the Print_r output is true when successful;
And Print_r can return Print_r-processed values by Print_r ($STR, true) so that Print_r does not output.

Can be understood as:
Print is a printed string

Print_r is the printing of composite types such as array objects, etc.

Execution rate in PHP from fast to Slow: Echo (), print (), Print_r ()

ECHO is a PHP statement, print and Print_r are functions, the statement does not return a value, the function can have a return value (even if it is not used)

Print () prints only the values of a simple type variable (such as int,string)
Print_r () can print out values for complex type variables (such as arrays, objects)


echo outputs one or more strings
echo--output one or more strings

Descrīption
void Echo (String arg1 [, String ...])//return value is empty

echo "Hello", "friend";
Print-Output a string

Descrīption
int print (string arg)//return value is reshape
print "Hello friend";

You can do the following
$name =print "Nihao \ n";
$STR = ' Test print value is $name. ';
Eval_r ("\ $print =\" $str \ ";");
Echo $print;

Print_r-Print easy-to-understand information about variables.


BOOL Print_r (mixed expression [, bool return])//Return value is Boolean, parameter is mix type, can be string, shape, array, object class Print_r () display easy-to-understand information about a variable. If a string, integer, or float is given, the variable value itself is printed. If an array is given, the keys and elements are displayed in a certain format. object is similar to an array.


Print_r () Moves the pointer of the array to the last edge.


You can
Print_r (str);
Print_r (int);
Print_r (array);
Print_r (obj);
You can also use Var_dump, Var_export


Echo ()
You can output multiple strings at the same time, multiple parameters, no parentheses, no return values.

Print ()
You can only output one string at a time, one argument, a parenthesis, a return value, and false if its execution fails. Print is used in a very similar way to the C language, so there is a special explanation for the% in the output content.
$a =print (' Hi ');
echo $a;
//----------------------------
Hi 1//1 is a $ A value.
//-----------------------------


Die (); and exit () difference.
There are two functions: output the content first, then exit the program. (commonly used in linked servers, databases)
Mysql_connect ("Locahost", "root", "root") or Die ("link server failed!") ");


printf (); F = Format formatted
printf ("Parameter 1", Parameter 2): Parameter 1 = output by what format; parameter 2= the output variable. (%s: by string;%d: by integer type;%b: by binary;%x: Press 16 to enter;%x: Press 16 to capitalize output;%o: press octal;%f: float type)
For parameter 1, the format is as follows:
%[' Padding_character][-][width][.precision]type


Description
All conversions start with%, and if you want to print a%, you must use "percent";
The parameter padding_character is optional and is used to fill the variable until the specified width, such as: printf ("$% ' a10.2f", 43.2); $AAAAA 43.20, the default is to fill a space, if you specify a space or 0 you do not need to use "'" as a prefix. Single quotation marks must be specified for any other prefix.
"-" is optional, and adding it indicates that the data should be left-aligned. Instead of the default right alignment, as in the previous example plus one-then: printf ("$% ' a-10.2f", 43.2); $43.20aaaaa
Whidth indicates how much space (in characters) is left for the variable to be replaced. As in the previous example, 10 (including the decimal point).
The precision must start with a decimal point, indicating the number of digits to be displayed after the number of decimals.
function, returns the number of output characters, and then formats the text for later output, such as:
printf ("$.2f", 43.2); $43.20
$ represents a populated character
0 indicates that the number of digits is not sufficient to complement 0 without affecting the original value
1 indicates the total width of the output
2 indicates the number of decimal digits, there is rounding
%f is indicated as a floating-point number

formatting commands and descriptions:
Percent percentage mark, not convert.


The%b integer is converted into binary.
The%c integer is converted to the corresponding ASCII character. such as: printf ("$%c", 65); Output: A
%d integers are converted to 10 decimal. such as: printf ("$%d", 65.53); Output: 65
%f times the precision number into floating point numbers.
%o The integer is turned into octal.
The%s integer is converted to a string.
%x integers are converted to lowercase 16 rounding.
%x integer turns into uppercase 16 rounding

For printf (), you can also specify the order of parameter conversions by using an argument that has an ordinal and ends with a $ symbol. Such as:
printf ("The total is $%2$.2f and subtotal:%1$.2f", 65.55,37.2); The total is $37.20 and subtotal:65.55


As above:%2$.2f Specifies the use of the second parameter 65.55,%1$.2f is specified with the first parameter 37.20.
Sqlmap file for the table fields and class properties of the database 4. Then create a new src\main\

http://www.bkjia.com/PHPjc/477935.html www.bkjia.com true http://www.bkjia.com/PHPjc/477935.html techarticle the difference between Echo and print is that echo can output multiple variable values, while print has only one variable as a string output. The other difference is that ECHO has no return value, print has a return value of 1.PR ...

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