[Basis of the PHP] difference between the echo / print / print_r

For a long time know print_r output when using a complex type, simply use echo, hereby today go into this question, what time to start with less direct echo, print, pinrt_f, nonsense

The first to write four types: plastic, strings, arrays, functions,

INTE $ = 2; // shaping 
$ STR = 'dwqdw'; // String 
$ ARR = [ '. 1', '2', '. 3']; // Array
// function 
function XX () {
     echo 123 ;
}
echo  $ not ;
print ( $ not );
print_r ( $ not );  

Results: 222, as output

var_dump ( echo  $ not );
var_dump ( print ( $ not ));
var_dump ( print_r ( $ not ));

Var_dump print using the three types of return,

Results: syntax error, unexpected 'echo' direct error o (╥﹏╥) o echo no return value, directly commented,

Summary: 2222int (1) 2bool (true) print returns 1, print_r returns true,

 

Start the next print string:

echo $str."<br>";
print($str)."<br>";
print_r($str)."<br>";

var_dump(echo $str)."<br>";
var_dump(print($str))."<br>";
var_dump(print_r($str))."<br>";

The results:. 1.var_dump (echo $ str) "<br>"; this is a direct error, echo-free return value, comment

   2.dwqdw dwqdw dwqdwdwqdwint (1) dwqdwbool ( true), a normal printing print returns 1, print_r returns true

Print array:

echo $arr."<br>";
print($arr)."<br>";
print_r($arr)."<br>";

var_dump(echo $arr)."<br>";
var_dump(print($arr))."<br>";
var_dump(print_r($arr))."<br>";

The results:.. 1 var_dump (echo $ arr) "<br>"; this is a direct error, echo-free return value, comment

      . 2.echo $ arr "<br>"; error; . Var_dump (echo $ arr) "<br>" ; error, Print ($ arr) "<br>";. Error var_dump (print ($ arr)) . "<br>"; error. Array to string conversion to convert the string array

Summary: pint echo not print array type

 

Print function type: lazy just say the results are only pinr_r other normal output can not print

Summary: 1.echo, print only print plastic, string type

      2.print_r can print a variety of types (that white is the type will do)

     3. echo return no value, print () Returns shaping 1, print_r () Boolean Returns true   

 

Guess you like

Origin www.cnblogs.com/baboben/p/11961669.html