Print,print_r,printf,sprintf,die,echo,var_dump, Var_export Difference
1 Echo ()
You can output multiple strings at the same time, multiple parameters, no parentheses, no return values.
2 print ()
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.
//??????????
3 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 ("
Linked server failed!
“);
4 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.
$num = 100.001;
printf ("%d", $num); 100
printf ("%s", $num); 100.001
printf ("%s?%d?%b?%x?%o?") %f ", $num, $num, $num, $num, $num, $num)
100.001?100?1100100?64?144?1001.00100
printf ("%.2f", $num); 100.00 (decimal point reserved 2 digits)
printf ("%.1f", $num); 100.0 (decimal point reserved 1 digits)
printf ("% ' #10s", $num); #10s
printf ("% #10s", $num); 10s
?>
5 sprintf ();
This cannot be output directly, first assigning a variable, and then outputting the variable.
$num = 100.001;
$a =sprintf ("%d", $num);
echo $a; 100
?>
6 Print_r ();
Function: Used only for output arrays.
$a = Array (1, 2, Array ("A", "B", "C"));
Print_r ($a);
Return:
Array ([0] = 1 [1] = 2 [2] = = Array ([0] + a [1] = + b [2] = c))
7 Var_dump ();
Function:
Output variable capacity, type, or string content, type, length. Commonly used to debug.
$a = 100;
Var_dump ($a); Int (100)
$a = 100.356;
Var_dump ($a); Float (100.356)
?>
8.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.
$a = Array (1, 2, Array ("A", "B", "C"));
Var_export ($a);
/*
Output:
Array (
0 = 1,
1 = 2,
2 =
Array (
0 = ' a ',
1 = ' B ',
2 = ' C ',
),
)
*/
$b = 3.1;
$v = Var_export ($b, TRUE);
Echo $v;
/*
Output:
3.1
*/
?>