Introduction to the usage of var_export and var_dump_PHP tutorial

WBOY
Release: 2016-07-13 17:14:31
Original
1498 people have browsed it

Now let’s introduce the usage of var_export and var_dump. Friends in need can refer to it.

var_export must return legal PHP code. In other words, the code returned by var_export can be directly assigned to a variable as PHP code. And this variable will get the same type of value as var_export

•However, when the variable type is resource, it cannot be copied simply. Therefore, when the variable of var_export is of resource type, var_export will return NULL

Example

The code is as follows Copy code
 代码如下 复制代码

$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

$res = yblog_mspconfiginit("ratings");
var_dump($res);
var_export($res);Result:

resource(1) of type (yahoo_yblog)
NULL Another example:
 代码如下 复制代码

//php var_export读写实例类
class user{
var $filepath;
function __()
{
$this->filepath = "d:/www.bKjia.c0m/group/";
 }
 function cache() {
  $array = $this->db->select('select group_id,group_name from group','hashmap');
  $fp = fopen ($this->filepath, 'w');
  fputs($fp, '');
  fclose($fp);
 }

 function getVar_export($value) {
  $array = require($this->filepath);
  foreach ($array as $key => $v) {
   if ($key==$value) {
    $selected = ' current option';
   } else {
    $selected = '';
   }
   $html .= '';
  }
 
  return $html;
 }
}

//使用实例方法

$g = new user();
if( intval( $_GET['iscreate']) )
{
 $g->cache();
}
else
{
 $g->getVar_export('vv');
}
//本站原创www.bKjia.c0m转载注明来源
?>

$res = fopen('status.html', 'r');
var_dump($res);
var_export($res);Result: resource(2) of type (stream)
NULL
Example
The code is as follows Copy code
//php var_export read and write instance class
class user{
var $filepath;
function __()
{
$this->filepath = "d:/www.bKjia.c0m/group/";
}
function cache() {
$array = $this->db->select('select group_id,group_name from group','hashmap');
$fp = fopen ($this->filepath, 'w');
fputs($fp, '');
fclose($fp);
} function getVar_export($value) {
$array = require($this->filepath);
foreach ($array as $key => $v) {
if ($key==$value) {
$selected = ' current option';
} else {
$selected = '';
}
$html .= '';
}

return $html;
}
} //Use instance method $g = new user();
if( intval( $_GET['iscreate']) )
{
$g->cache();
}
else
{
$g->getVar_export('vv');
}
//This site’s original www.bKjia.c0m reprints indicate the source
?>

For more details, please check: http://www.bKjia.c0m/phper/21/02496253b66d66ca613a2f19ea40c22e.htm


var_dump function
var_dump  (PHP 3 >= 3.0.5, PHP 4, PHP 5)  

var_dump -- Print information about variables

void var_dump ( mixed expression [, mixed expression [, ...]] )

This function displays structural information about one or more expressions, including the type and value of the expression. Arrays will expand values ​​recursively, showing their structure through indentation. ​

Tip: To prevent the program from outputting the results directly to the browser, you can use output-control functions to capture the output of this function and save them to a variable of type string, for example. ​


You can compare var_dump() and print_r().


Example

 
</tr>
</table> <?php</p>
<p align="left"> $a = array (1, 2, array ("a", "b", "c"));<div style="display:none;">
<span id="url" itemprop="url"> var_dump ($a);</span>
<span id="indexUrl" itemprop="indexUrl"> /* Output: </span>
<span id="isOriginal" itemprop="isOriginal"> array(3) {</span>
<span id="isBasedOnUrl" itemprop="isBasedOnUrl"> [0]=>
<span id="genre" itemprop="genre">int(1)</span>
<span id="description" itemprop="description"> [1]=></span>
int(2)
 [2]=><div class="art_confoot">
</div> array(3) {
 [0]=>
 String(1) "a"
 [1]=>
 String(1) "b"
 [2]=>
 String(1) "c"
 }
 }
 */
 $b = 3.1;
 $c = TRUE;
 var_dump($b,$c);
 /* Output: 
 float(3.1)
bool(true)
 */
 ?>
 
For more details, please check: http://www.bKjia.c0m/phper/php/43382.htm http://www.bkjia.com/PHPjc/628989.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628989.htmlTechArticleLet’s introduce the usage of var_export and var_dump. Friends in need can refer to it. var_export must return legal php code, that is, the code returned by var_export,...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
The code is as follows
 代码如下 复制代码

 代码如下 复制代码

  

</p>
<p>  <?php</p>
<p>  $a = array (1, 2, array ("a", "b", "c"));</p>
<p>  var_dump ($a);</p>
<p>  /* 输出:</p>
<p>  array(3) {</p>
<p>  [0]=></p>
<p>  int(1)</p>
<p>  [1]=></p>
<p>  int(2)</p>
<p>  [2]=></p>
<p>  array(3) {</p>
<p>  [0]=></p>
<p>  string(1) "a"</p>
<p>  [1]=></p>
<p>  string(1) "b"</p>
<p>  [2]=></p>
<p>  string(1) "c"</p>
<p>  }</p>
<p>  }</p>
<p>  */</p>
<p>  $b = 3.1;</p>
<p>  $c = TRUE;</p>
<p>  var_dump($b,$c);</p>
<p>  /* 输出:</p>
<p>  float(3.1)</p>
<p>  bool(true)</p>
<p>  */</p>
<p>  ?></p>
<p>  

Copy code

The code is as follows. Copy the code