Echo (); "Output content";
You can output multiple strings at the same time, multiple parameters, no parentheses, no return values.
print (); Has a return value of 1, 0 tangent can only contain one parameter
You can only output one string at a time, one parameter, a parenthesis, a return value, and flase when 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 the value of $a. —————————–
Die (); Generally used for database connection judgment, once the execution of Die () after the content will not be executed
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 (); As with the C language, you can format the output
printf (); F = Format formatted
printf ("parameter 1″, parameter 2): Parameter 1 = output by what format; parameter 2= output variable.
(% s: by string;%d: by integer type;%b: press binary;% x: Press 16 to enter;%x: Press 16 to capitalize the output;%o: press octal;% f: float type)
function, returns the number of output characters, and then formats the text for later output, such as:
printf ("$%01.2f", 43.2); $43.20
$ represents a populated character
0 indicates that the number of digits does not affect the original value in the case of
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.
%d integers are converted to 10 decimal.
%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 integers are converted to uppercase 16 rounding.
<?php$num=100.001;printf ("%d", $num); 100printf ("%s", $num); 100.001printf ("%s-%d-%b-%x-%o-%f", $num, $num, $num, $num, $num, $num)//100.001-100-1100100-64-144- 1001.00100printf ("%.2f", $num); 100.00 (decimal point reserved 2 digits) printf ("%.1f", $num); 100.0 (decimal point reserved 1 digits) printf ("% ' #10s", $num); #10sprintf ("% #10s", $num); 10s?>
sprintf; Store the output in a variable
This cannot be output directly, first assigning a variable, and then outputting the variable.
<?php$num=100.001; $a =sprintf ("%d", $num); Echo $a; 100?>
Print_r (); For output arrays
Function: Used only for output arrays.
$a = Array (1, 2, Array ("A", "B", "C"));p Rint_r ($a);
Return:
Array ([0] = 1 [1] = 2 [2] = = Array ([0] + a [1] = + b [2] = c))
var_dump (); Can output any Content
Output variable capacity, type, or string content, type, length. Commonly used to debug.
<?php$a=100;var_dump ($a); Int (+) $a =100.356;var_dump ($a); Float (100.356)?>
Var_export ();
Returns the structure information about the variable passed to the function, similar to Var_dump (), unlike the PHP code whose returned representation is valid.
You can return the value of a variable by setting the second argument of the function to true.
<?php$a = Array (1, 2, Array ("A", "B", "C")), Var_export ($a);/* Output: Array (0 = 0 = 2,2 =>array , 1 = ' B ', 2 = ' C ',),) */$b = 3.1; $v = Var_export ($b, TRUE); echo $v;/* Output:3.1*/?>
Simplified usage:
<?php$color = "Red";? ><p>roses is <?= $color?></p>