int print ( string $arg ) 输出 arg print 实际上不是一个函数(它是一个语言结构),因此你可以不必使用圆括号来括起它的参数列表
arg:输入数据
总是返回 1
<?php $str = "Hello World"; print $str; ?>
输出:
Hello World
<?php $str = "Hello World"; print $str; print "<br>Hello PHP7"; ?>
输出:
Hello World Hello PHP7
<?php $str1 = "Hello World"; $str2 = "<br>Hello PHP7"; print $str1 . " " . $str2; ?>
输出:
Hello World Hello PHP7
<?php $str1 = "Hello World"; $str2 = "Hello PHP7"; print "$str1 <br> $str2"; ?>
输出:
Hello World Hello PHP7
<?php print "This text spans multiple lines."; ?>
输出:
This text spans multiple lines.
<?php $color = "red"; print "Roses are $color"; print "<br>"; print 'Roses are $color'; ?>
输出:
Roses are red Roses are $color
bool print r ( mixed $expression [, bool $return ] ) 打印关于变量的易于理解的信息 如果给出的是 string、integer 或 float,将打印变量值本身;如果给出的是 array,将会按照一定格式显示键和元素;object 与数组类似 注意,print r() 将把数组的指针移到最后边,使用 reset() 可让指针回到开始处
expression:输入数据。mix类型,可以是字符串,整形,数组,对象类 return:true将结果存入返回值中,false直接打印结果
return为true时返回1,return为false时返回输出结果
<?php $str = "Hello world"; $ret = 0; $output = print_r("$str <br>", $ret); print "$output <br>"; ?>
输出:
Hello world 1
<?php $str = "Hello world"; $ret = 1; $output = print_r("$str <br>", $ret); print "$output <br>"; ?>
输出:
Hello world
<?php $arr = array(1, 2, 3); print_r($arr); ?>
输出:
Array ( [0] => 1 [1] => 2 [2] => 3 )
<?php $obj = new mysqli(); print_r($obj); ?>
输出: >mysqli Object ( [affected_rows] => [client_info] => 5.5.39 [client_version] => 50539 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => [field_count] => [host_info] => [info] => [insert_id] => [server_info] => [server_version] => [stat] => [sqlstate] => [protocol_version] => [thread_id] => [warning_count] => )