下面我们来介绍一下关于var_export 与 var_dump用法,有需要的朋友可参考.var_export必须返回合法的php代码, 也就是说,var_export返回的代码,可以直接当作php代码赋值个一个变量. 而这个变量就会取得和被var_export一样的类型的值
但是, 当变量类型为resource的时候, 是无法简单copy复制的,所以, 当var_export的变量是resource类型时, var_export会返回NULL
实例代码如下:
$res = yblog_mspconfiginit("ratings"); var_dump($res); var_export($res);结果: resource(1) of type (yahoo_yblog)
NULL再比如:
$res = fopen('status.html', 'r'); var_dump($res); var_export($res);结果: resource(2) of type (stream) NULL
实例代码如下:
<?php //php var_export读写实例类 class user { var $filepath; function __() { $this->filepath = "d:/www.phprm.com/group/"; } function cache() { $array = $this->db->select('select group_id,group_name from group', 'hashmap'); $fp = fopen($this->filepath, 'w'); fputs($fp, '<?php return ' . var_export($array, true) . ';'); fclose($fp); } function getVar_export($value) { $array = require ($this->filepath); foreach ($array as $key => $v) { if ($key == $value) { $selected = ' current option'; } else { $selected = ''; } $html.= '<option value="' . $key . '"' . $selected . '>' . $v . '</option>'; } return $html; } } //使用实例方法 $g = new user(); if (intval($_GET['iscreate'])) { $g->cache(); } else { $g->getVar_export('vv'); } //本站原创www.phprm.com转载注明来源 var_dump函数var_dump (PHP3 >= 3.0.5, PHP4, PHP5) var_dump--打印变量的相关信息voidvar_dump(mixedexpression[, mixedexpression[, . . . ]]) ?>
此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值.数组将递归展开值,通过缩进显示其结构.
提示: 为了防止程序直接将结果输出到浏览器,可以使用输出控制函数(output-control functions)来捕获此函数的输出,并把它们保存到一个例如 string 类型的变量中.
可以比较一下 var_dump() 与 print_r().
实例代码如下:
<pre class="brush:php;toolbar:false"> <?php $a = array( 1, 2, array( "a", "b", "c" ) ); var_dump($a); /* 输出: array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } } */ $b = 3.1; $c = TRUE; var_dump($b, $c); /* 输出: float(3.1) bool(true) */ ?>
文章链接:
随便收藏,请保留本文地址!

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

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.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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

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

SublimeText3 Linux new version
SublimeText3 Linux latest version
