Home Backend Development PHP Tutorial Introduction to the usage of var_export and var_dump_PHP tutorial

Introduction to the usage of var_export and var_dump_PHP tutorial

Jul 13, 2016 pm 05:14 PM
dump export var one time under and introduce about us use usage

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,...
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
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)

Analyze the usage and classification of JSP comments Analyze the usage and classification of JSP comments Feb 01, 2024 am 08:01 AM

Classification and Usage Analysis of JSP Comments JSP comments are divided into two types: single-line comments: ending with, only a single line of code can be commented. Multi-line comments: starting with /* and ending with */, you can comment multiple lines of code. Single-line comment example Multi-line comment example/**This is a multi-line comment*Can comment on multiple lines of code*/Usage of JSP comments JSP comments can be used to comment JSP code to make it easier to read

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.

Usage of WPSdatedif function Usage of WPSdatedif function Feb 20, 2024 pm 10:27 PM

WPS is a commonly used office software suite, and the WPS table function is widely used for data processing and calculations. In the WPS table, there is a very useful function, the DATEDIF function, which is used to calculate the time difference between two dates. The DATEDIF function is the abbreviation of the English word DateDifference. Its syntax is as follows: DATEDIF(start_date,end_date,unit) where start_date represents the starting date.

How to correctly use the exit function in C language How to correctly use the exit function in C language Feb 18, 2024 pm 03:40 PM

How to use the exit function in C language requires specific code examples. In C language, we often need to terminate the execution of the program early in the program, or exit the program under certain conditions. C language provides the exit() function to implement this function. This article will introduce the usage of exit() function and provide corresponding code examples. The exit() function is a standard library function in C language and is included in the header file. Its function is to terminate the execution of the program, and can take an integer

Introducing the latest Win 11 sound tuning method Introducing the latest Win 11 sound tuning method Jan 08, 2024 pm 06:41 PM

After updating to the latest win11, many users find that the sound of their system has changed slightly, but they don’t know how to adjust it. So today, this site brings you an introduction to the latest win11 sound adjustment method for your computer. It is not difficult to operate. And the choices are diverse, come and download and try them out. How to adjust the sound of the latest computer system Windows 11 1. First, right-click the sound icon in the lower right corner of the desktop and select "Playback Settings". 2. Then enter settings and click "Speaker" in the playback bar. 3. Then click "Properties" on the lower right. 4. Click the "Enhance" option bar in the properties. 5. At this time, if the √ in front of "Disable all sound effects" is checked, cancel it. 6. After that, you can select the sound effects below to set and click

PyCharm Beginner's Guide: Comprehensive Analysis of Replacement Functions PyCharm Beginner's Guide: Comprehensive Analysis of Replacement Functions Feb 25, 2024 am 11:15 AM

PyCharm is a powerful Python integrated development environment with rich functions and tools that can greatly improve development efficiency. Among them, the replacement function is one of the functions frequently used in the development process, which can help developers quickly modify the code and improve the code quality. This article will introduce PyCharm's replacement function in detail, combined with specific code examples, to help novices better master and use this function. Introduction to the replacement function PyCharm's replacement function can help developers quickly replace specified text in the code

Detailed explanation and usage introduction of MySQL ISNULL function Detailed explanation and usage introduction of MySQL ISNULL function Mar 01, 2024 pm 05:24 PM

The ISNULL() function in MySQL is a function used to determine whether a specified expression or column is NULL. It returns a Boolean value, 1 if the expression is NULL, 0 otherwise. The ISNULL() function can be used in the SELECT statement or for conditional judgment in the WHERE clause. 1. The basic syntax of the ISNULL() function: ISNULL(expression) where expression is the expression to determine whether it is NULL or

How to use Apple shortcuts How to use Apple shortcuts Feb 18, 2024 pm 05:22 PM

How to use Apple shortcut commands With the continuous development of technology, mobile phones have become an indispensable part of people's lives. Among many mobile phone brands, Apple mobile phones have always been loved by users for their stable systems and powerful functions. Among them, the Apple shortcut command function makes users’ mobile phone experience more convenient and efficient. Apple Shortcuts is a feature launched by Apple for iOS12 and later versions. It helps users simplify their mobile phone operations by creating and executing custom commands to achieve more efficient work and

See all articles
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