Print_r()PHP函数

An array in PHP computer programming contains a group of similar objects that are the same type and size. The array can contain integers, characters, or anything else with a defined data type.

PHP计算机编程中的数组包含一组类型和大小相同的相似对象。 该数组可以包含整数,字符或具有定义的数据类型的其他任何内容。

The print_r PHP function is used to return an array in a human readable form. It is written as:

PHP的print_r函数用于以人类可读的形式返回数组。 它写为:


pri

In this example, an array is defined and printed. The tag <pre> indicates the following code is preformatted text. This tag causes the text to be displayed in a fixed-width font. It preserves line breaks and spaces, making it easier for the human observer to read.

在此示例中,定义并打印了一个数组。 标记<pre>表示以下代码是预格式化的文本。 此标记使文本以固定宽度的字体显示。 它保留了换行符和空格,使人类观察者更易于阅读。


<pre>
<?php
$Names = array ('a' => 'Angela', 'b' => 'Bradley', 'c' => array ('Cade', 'Caleb'));
print_r ($Names);
?>
</pre>

When the code is run, the results looks like this:

运行代码时,结果如下所示:

Array([a] => Angela[b] => Bradley[c] => Array([0] => Cade[1] => Caleb))

Array([a] => Angela [b] => Bradley [c] => Array([0] => Cade [1] => Caleb))

Print_r的变体 ( Variations of Print_r )

You can store the result of print_r in a variable with a second parameter to print_r. This technique prevents any output from the function.

您可以将print_r的结果存储在带有第二个参数print_r的变量中。 此技术可防止函数输出任何信息。

Augment the function of print_r with var_dump and var_export to show protected and private properties of the objects, including type and value. The difference of the two is that var_export returns valid PHP code, whereas var_dump does not.

使用var_dumpvar_export增强print_r的功能,以显示对象的受保护和私有属性,包括类型和值。 两者的区别在于var_export返回有效PHP代码,而var_dump则不。

用于PHP ( Uses for PHP )

PHP is a server-side language used to add enhanced features to a website developed in HTML, such as surveys, shopping carts, login boxes, and CAPTCHA codes. You can use it to build an online community, integrate Facebook with your website, and generate PDF files. With PHP's file-handling functions, you can create photo galleries and you can use the GD library included with PHP to generate thumbnail images, add watermarks, and resize and crop images.

PHP是一种服务器端语言,用于向HTML开发的网站添加增强功能,例如调查,购物车,登录框和CAPTCHA代码。 您可以使用它来建立在线社区,将Facebook与您的网站集成以及生成PDF文件。 借助PHP的文件处理功能,您可以创建照片库,并且可以使用PHP附带的GD库来生成缩略图,添加水印以及调整大小和裁剪图像。

If you host banner ads on your website, PHP rotates them at random. The same feature can be used to rotate quotations. It is easy to set up page redirects using PHP and if you are wondering how often your visitors check out your website, use PHP to set up a counter.

如果您在网站上托管横幅广告,PHP将随机旋转它们。 可以使用相同的功能来旋转报价。 使用PHP设置页面重定向很容易,如果您想知道访问者多久访问一次您的网站,请使用PHP设置计数器。

翻译自: https://www.thoughtco.com/printr-php-function-2694083

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值