PHP中echo(),print(),print_r()的差别
PHP中echo(),print(),print_r()的区别
echo ,print的区别在于echo 可以输出多个变量值,而print只有一个变量,做为一个字符串输出. 另一点区别在于echo 没有返回值,print有返回值1.print不能输出数组和对象。
print_r可以输出stirng、int、float、array、object等,输出array时会用结构表示,print_r输出成功时返回true;
而且print_r可以通过print_r($str,true)来使print_r不输出而返回 print_r处理后的值。
可以理解为:
print 是打印字符串
print_r 则是打印复合类型 如数组 对象等
在PHP中的执行速率从快到慢为:echo(), print(), print_r()
echo是PHP语句, print和print_r是函数,语句没有返回值,函数可以有返回值(即便没有用)
print() 只能打印出简单类型变量的值(如int,string)
print_r() 可以打印出复杂类型变量的值(如数组,对象)
echo 输出一个或者多个字符串
echo -- 输出一个或者多个字符串
Descrīption
void echo ( string arg1 [, string ...] ) //返回值为空
echo "你好"," 朋友";
print --输出一个字符串
Descrīption
int print ( string arg )//返回值为整形
print "你好朋友";
可以进行下面操作
$name=print "nihao \n";
$str = 'test print value is $name .';
eval_r("\$print=\"$str\";");
echo $print;
print_r -- 打印关于变量的易于理解的信息。
bool print_r ( mixed expression [, bool return] ) //返回值是布尔型的,参数是mix类型的,可以是字符串,整形,数组,对象类print_r() 显示关于一个变量的易于理解的信息。如果给出的是 string、integer 或 float,将打印变量值本身。如果给出的是 array,将会按照一定格式显示键和元素。object 与数组类似。
print_r() 将把数组的指针移到最后边。
你可以
print_r(str);
print_r(int);
print_r(array);
print_r(obj);
也 可以用var_dump, var_export
echo()
可以同时输出多个字符串,可以多个参数,并不需要圆括号,无返回值。
print()
只可以同时输出一个字符串,一个参数,需要圆括号,有返回值,当其执行失败时返false . print 的用法和C语言很像,所以会对输出内容里的%做特殊解释。
$a=print('hi');
echo $a;
//----------------------------
hi 1 //1是$a的值。
//-----------------------------
die(); // 和exit()区别。
有两个功能:先输出内容,然后退出程序。(常用在链接服务器,数据库)
mysql_connect("locahost","root","root") or die("链接服务器失败!");
printf(); //f指format格式化
printf("参数1",参数2):参数1=按什么格式输出;参数2=输出的变量。(%s:按字符串;%d: 按整型;%b:按二进制;%x:按16进制;%X:按16进制大写输出;%o:按八进制; %f:按浮点型)
对于参数1,其格式如下:
%[ 'padding_character][-][width][.precision]type
说明:
所有转换都以%开头,如果想打印一个%,则必须用“%%”;
参数padding_character是可选的,用来填充变量直至指定的宽度,如:printf ("$%'a10.2f" , 43.2); //$aaaaa43.20,默认是填充一个空格,如果指定了一个空格或0就不需要使用“'”做为前缀。对于任何其它前缀则必须指定单引号。
【-】是可选的,添加它则表明数据应该左对齐。而不是默认的右对齐,如上例加一个-则为:printf ("$%'a-10.2f" , 43.2); //$43.20aaaaa
whidth 表示在这里为将被替换的变量留下多少空间(按字符计算)。如上例的10(包括小数点).
precision则必须是一个小数点开始,表示小数位后面要显示的位数。
函数,返回输出字符个数,把文字格式化以后输出,如:
printf ("$.2f" , 43.2); //$43.20
$表示填充的字符
0表示位数不够在不影响原值的情况下补0
1表示输出的总宽度
2表示小数位数,有四舍五入
%f 是表示显示为一个浮点数
格式化命令及说明:
%% 印出百分比符号,不转换。
%b 整数转成二进位。
%c 整数转成对应的 ASCII 字符。 如:printf ("$%c" , 65); // 输出:A
%d 整数转成十进位。 如:printf ("$%d" , 65.53); // 输出:65
%f 倍精确度数字转成浮点数。
%o 整数转成八进位。
%s 整数转成字符串。
%x 整数转成小写十六进位。
%X 整数转成大写十六进位
对于printf(),还可以使用带序号并以$符号结束的参数方式来指定参数转换的顺序。如:
printf ("the total is $%2$.2f and subtotal: %1$.2f" , 65.55,37.2); //the total is $37.20 and subtotal: 65.55
如上:%2$.2f指定了使用第二个参数65.55,%1$.2f则指定用第一个参数37.20。
数据库的表字段和类属性的 sqlmap文件4.然后新建src\main\

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

The activation process on Windows sometimes takes a sudden turn to display an error message containing this error code 0xc004f069. Although the activation process is online, some older systems running Windows Server may experience this issue. Go through these initial checks, and if they don't help you activate your system, jump to the main solution to resolve the issue. Workaround – close the error message and activation window. Then restart the computer. Retry the Windows activation process from scratch again. Fix 1 – Activate from Terminal Activate Windows Server Edition system from cmd terminal. Stage – 1 Check Windows Server Version You have to check which type of W you are using
