首页 > 代码库 > PHP输出打印方法

PHP输出打印方法

PHP输出打印方法

 

 

1. echo()输出字符串,PHP允许我们在双引号串中直接包含字串变量,而单引号串中的内容总被认为是普通字符。

  

2. mixed print_r ( mixed $expression [, bool $return = false ] ) 打印变量  print_r — Prints human-readable information about a variable  print_r打印普通字符串会报错

void var_dump ( mixed $expression [, mixed $... ] )打印变量的详细信息   var_dump — Dumps information about a variable

<?php
	$arr=array(array(‘a‘=>‘aa‘,‘b‘=>‘bbb‘,‘c‘=>‘ccc‘),
	           array(‘a‘=>‘ddd‘,‘b‘=>‘eee‘,‘c‘=>‘fff‘),
	           array(‘a‘=>‘gg‘,‘b‘=>‘hh‘));
	echo ‘======= print_r($arr)======= ‘;      //使用单引号‘‘
	echo ‘<br />‘;
	print_r($arr);
	echo ‘<br />‘;
	echo ‘======= var_dump($arr)======= ‘;
	echo ‘<br />‘;
	var_dump($arr);
?>

  

输出结果:

======= print_r($arr)======= 
Array ( [0] => Array ( [a] => aa [b] => bbb [c] => ccc ) [1] => Array ( [a] => ddd [b] => eee [c] => fff ) [2] => Array ( [a] => gg [b] => hh ) ) 
======= var_dump($arr)======= 
array (size=3)
0 => 
array (size=3)
‘a‘ => string ‘aa‘ (length=2)
‘b‘ => string ‘bbb‘ (length=3)
‘c‘ => string ‘ccc‘ (length=3)
1 => 
array (size=3)
‘a‘ => string ‘ddd‘ (length=3)
‘b‘ => string ‘eee‘ (length=3)
‘c‘ => string ‘fff‘ (length=3)
2 => 
array (size=2)
‘a‘ => string ‘gg‘ (length=2)
‘b‘ => string ‘hh‘ (length=2)

 

PHP输出打印方法