PHP echo,print_r(expression),var_dump(expression)区别,print_rvar_dump
三者都是具有输出功能的php语句,但print_r(expression),var_dump(expression)是函数,echo只是语言结构,不是函数,因此不能作为表达式的一部分。
对于php的8中数据类型,
echo ‘输出一个字符串’;//只可以输出字符串和数字
print_r — 打印关于变量的易于理解的信息,一般用输出数组结构
var_dump — 打印变量的相关信息,一般用于数组和对象打印
自己用一下就清楚了
四种方法可以输出字符串。 echo
print()
printf()
print_r()
echo
可以一次输出多个值,多个值之间用逗号分隔。echo是语言结构(language construct),而并不是真正的函数,因此不能作为表达式的一部分使用。
语法正确: echo "Hello", "World";
语法错误: echo ("Hello", "World");
print()
函数print()打印一个值(它的参数),如果字符串成功显示则返回true,否则返回false。如, if (!print("Hello, World")){
die("you are not listening to me");
}
printf()
printf()源于C语言中的printf()。该函数输出格式化的字符串。
语法: printf(format,arg1,arg2,arg++)
format 规定字符串以及如何格式化其中的变量;
arg1, arg2, ++ 等参数将插入到主字符串中的百分号 (%) 符号处。该函数是逐步执行的。在第一个 % 符号中,插入 arg1,在第二个 % 符号处,插入 arg2,依此类推。
Example: ?php
$str = "Hello";
$number = 123;
printf("%s world. Day number %u",$str,$number);
?>
#Results======
Hello world. Day number 123
如果 % 符号多于 arg 参数,则您必须使用占位符。占位符被插入 % 符号之后,由数字和 "\$" 组成。请参见例子 3。
Example: ?php
$number = 123;
printf("With 2 decimals: %1\$.2fbr />With no decimals: %1\$u",$number);
?>
#Result
With 2 decimals: 123.00
With no decimals: 123
print_r()和var_dump()
print_r()可以把字符串和数字简单地打印出来,而数组则以括起来的键和值得列表形式显示,并以Array开头。如, $a = array('name' => 'Fred', 'age' => '15', 'wife' => 'Wilma');
print_r($a);
Output: Array
{
[name] => Fred
[age] => 15
[wife] => Wilma
}
对象也一样。如, class P {
var $name = 'nat';
// ...
}
$p = new P;
print_r($p);
Output: Object
{
[name] => nat
}
但print_r()输出布尔值和NULL的结果没有意义,因为都是打印&quo......余下全文>>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)
