<?php $x = print("Hello World"); // 输出 Hello World echo$x; // 输出 1 print"Hello World"; //输出 Hello World ?>
printf printf主要用来格式化字符串
1 2 3 4
<?php printf("First %s %s。","hello", "world"); // First hello world printf("This is %1\$s %1\$s","A", "B"); //输出 This is A A,因为只显示第一个参数两次,而没有用到第二个参数 ?>
sprintf 和printf一样,但是没有输出,而只是格式化字符串
1 2 3 4
<?php printf(“First %s %s。”,”hello”, “world”); // First hello world printf(“This is %1\$s %1\$s”,”A”, “B”); //输出 This is A A,因为只显示第一个参数两次,而没有用到第二个参数 ?>
print_r 主要用来将数组、对象等数据类型以更易展示的形式输出来
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php $a = array ('a' => 'A', 'b' => 'B', 'c' => array ('a','b','c')); print_r ($a); ?> 结果如下: Array ( [a] => A [b] => B [c] => Array ( [0] => a [1] => b [2] => c ) )
<?php $age = 20; $str1 = 'I am $age years old'; $str2 = "I am $age years old"; echo$str1,'<br />'; //输出: I am $age years old; echo$str2,'<br />'; // 输出:I am 20 years old; ?>