Home Backend Development PHP Tutorial echo(),print(),print_r(),var_dump()的区别,该怎么处理

echo(),print(),print_r(),var_dump()的区别,该怎么处理

Jun 13, 2016 pm 01:34 PM
dump echo print quot var

echo(),print(),print_r(),var_dump()的区别
echo(),print(),print_r(),var_dump()的区别

------解决方案--------------------
1.echo
输出一个或者多个字符串。
2.print
和echo一样,速度比echo慢。
3.print_r
打印关于变量的易于理解的信息,如果给出的是 string、integer 或 float,将打印变量值本身。如果给出的是 array,将会按照一定格式显示键和元素。object 与数组类似。 记住,print_r() 将把数组的指针移到最后边。使用 reset() 可让指针回到开始处。
4.var_dump
此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值。数组将递归展开值,通过缩进显示其结构。
5.var_dump和print_r的区别
var_dump返回表达式的类型与值而print_r仅返回结果,相比调试代码使用var_dump更便于阅读。
------解决方案--------------------
- echo
是命令,不能返回值。echo后面可以跟很多个参数,之间用分号隔开,如:

echo $myvar1;
echo 1,2,$myvar,"bold";

- print
是函数,可以返回一个值,只能有一个参数。

- printf
函数,把文字格式化以后输出,如:

$name="hunte";
$age=25;
printf("my name is %s, age %d", $name, $age);

- sprintf
跟printf相似,但不打印,而是返回格式化后的文字,其他的与printf一样。

- print_r
print_r通常用于打印变量的相关信息,通常在调试中使用。

print_r(true); //输出1
print_r(false); //没有输出
print_r(null); //没有输出

- var_dump
var_dump此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值。

var_dump(true); //输出 bool(true)
var_dump(false); // bool(false)
var_dump(null); // bool(null)
var_dump()和print_r()的区别:
var_dump返回表达式的类型与值而print_r仅返回结果,相比调试代码使用var_dump更便于阅读。
------解决方案--------------------
①echo:命令,不能返回值。echo后面可以跟很多个参数,之间用分号隔开;用点号进行连接,如:

echo $myvar1;
echo 1,2,$myvar,"bold";

 ② print:函数,可以返回一个值,只能有一个参数。

 ③printf:函数,把文字格式化以后输出,如:

$name="hunte";
$age=25;
printf("my name is %s, age %d", $name, $age); 

%% - 返回百分比符号
%b - 二进制数
%c - 依照 ASCII 值的字符
%d - 带符号十进制数
%e - 可续计数法(比如 1.5e+3)
%u - 无符号十进制数
%f - 浮点数(local settings aware)
%F - 浮点数(not local settings aware)
%o - 八进制数
%s - 字符串
%x - 十六进制数(小写字母)
%X - 十六进制数(大写字母) 

 ④sprintf:跟printf相似,但不打印,而是返回格式化后的文字,其他的与printf一样。

 ⑤print_r:通常用于打印变量的相关信息,通常在调试中使用。

print_r(true); //输出1
print_r(false); //没有输出
print_r(null); //没有输出 

 ⑥var_dump:此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值。

var_dump(true); //输出 bool(true)
var_dump(false); // bool(false)
var_dump(null); // bool(null) 

 ⑦var_dump()和print_r()的区别:
var_dump返回表达式的类型与值而print_r仅返回结果,相比调试代码使用var_dump更便于阅读。

------解决方案--------------------
大致区别如楼上各位所说
另外纠正一下 print() 并不是函数 虽然可以带括号并且有返回值
http://docs.php.net/manual/zh/function.print.php

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
What is a dump file? What is a dump file? Jan 12, 2024 pm 04:58 PM

A dump file usually refers to a binary file, also known as a dump file or core dump file. This kind of file is generated by the computer system when it encounters a serious error or abnormal situation. It is used to store the status, stack, registers, memory images, logs and other information of the system or application.

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

In today's era of rapid technological development, programming languages ​​are springing up like mushrooms after a rain. One of the languages ​​that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Jun 13, 2023 pm 05:01 PM

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets

What are the most popular golang frameworks on the market? What are the most popular golang frameworks on the market? Jun 01, 2024 pm 08:05 PM

The most popular Go frameworks at present are: Gin: lightweight, high-performance web framework, simple and easy to use. Echo: A fast, highly customizable web framework that provides high-performance routing and middleware. GorillaMux: A fast and flexible multiplexer that provides advanced routing configuration options. Fiber: A performance-optimized, high-performance web framework that handles high concurrent requests. Martini: A modular web framework with object-oriented design that provides a rich feature set.

Detailed explanation of the role and usage of the echo keyword in PHP Detailed explanation of the role and usage of the echo keyword in PHP Jun 28, 2023 pm 08:12 PM

Detailed explanation of the role and usage of the echo keyword in PHP PHP is a widely used server-side scripting language, which is widely used in web development. The echo keyword is a method used to output content in PHP. This article will introduce in detail the function and use of the echo keyword. Function: The main function of the echo keyword is to output content to the browser. In web development, we need to dynamically present data to the front-end page. At this time, we can use the echo keyword to output the data to the page. e

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

18 Ways to Fix Audio Service Not Responding Issue on Windows 11 18 Ways to Fix Audio Service Not Responding Issue on Windows 11 Jun 05, 2023 pm 10:23 PM

Audio output and input require specific drivers and services to work as expected on Windows 11. These sometimes end up running into errors in the background, causing audio issues like no audio output, missing audio devices, distorted audio, etc. How to Fix Audio Service Not Responding on Windows 11 We recommend you to start with the fixes mentioned below and work your way through the list until you manage to resolve your issue. The audio service may become unresponsive for a number of reasons on Windows 11. This list will help you verify and fix most issues that prevent audio services from responding on Windows 11. Please follow the relevant sections below to help you through the process. Method 1: Restart the audio service. You may encounter

Let's talk about the differences between var, let and const (code example) Let's talk about the differences between var, let and const (code example) Jan 06, 2023 pm 04:25 PM

This article brings you relevant knowledge about JavaScript. It mainly introduces the differences between var, let and const, as well as the relationship between ECMAScript and JavaScript. Interested friends can take a look at it. I hope Helpful to everyone.

See all articles