1 Echo (); 2 print (); 3 Die (); 4 printf (); 5 sprintf (); 6 print_r (); 7 var_dump ();
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 similar way to the C language, so there is a special explanation for the% in the output content.
3 Die ();
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!") ");
4 printf ();
printf ("Parameter 1", Parameter 2): Parameter 1 = output by what format; parameter 2= the output variable. ($s: by string, $d: by Integer, $b: by Binary, $x: by 16, $o: by octal; $f: by floating-point type)
<?php
$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------1100100------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); # # #100.001
printf ("% ' @10s", $num); @@@100.001
printf ("% ' _10s", $num); ___100.001
printf ("% ' #-10s", $num); 100.001###
printf ("% ' @-10s", $num); [Email protected]@@
printf ("% ' _-10s", $num); 100.001___
printf ("% ' #20s", $num); ############ #100.001
?>
5 sprintf ();
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
?>
6 Print_r ();
Function: Used only for output arrays.
7 Var_dump ();
Function: Output variable content, type, or string content, type, length. Commonly used to debug.
<?php
$a = 100;
Var_dump ($a); Int (3) 100
?>
PHP output function