Next we will introduce the usage of var_export and var_dump. if you need it, please refer to it. Var_export must return valid php code, that is, the code returned by var_export can be directly assigned a variable as a php code. And this variable is
Next we will introduce the usage of var_export and var_dump. if you need it, please refer. var_export must return valid php code, that is, the code returned by var_export can be directly assigned a variable as a php code. and this variable will get the same type value as var_export.
However, when the variable type is resource, it cannot be simply copied. Therefore, when the var_export variable is resource type, var_export returns NULL.
The instance code is as follows:
- $ Res = yblog_mspconfiginit ("ratings ");
- Var_dump ($ res );
- Var_export ($ res); result:
- Resource (1) of type (yahoo_yblog)
- NULL, for example:
- $ Res = fopen('status.html ', 'r ');
- Var_dump ($ res );
- Var_export ($ res); result:
- Resource (2) of type (stream)
- NULL
The instance code is as follows:
- // Php var_export read/write instance class
- Class user {
- Var $ filepath;
- Function __()
- {
- $ This-> filepath = "d:/www.111cn.net/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. =' '. $ V .'';
- }
-
- Return $ html;
- }
- }
- // Use the instance method
- $ G = new user ();
- If (intval ($ _ GET ['iscreate'])
- {
- $ G-> cache ();
- }
- Else
- {
- $ G-> getVar_export ('vv ');
- }
- // Original site www.111cn.net reprinted to indicate the source
- ?>
Var_dump function
Var_dump (PHP 3> = 3.0.5, PHP 4, PHP 5)
Var_dump -- print information about a variable
Void var_dump (mixed expression [, mixed expression [,...])
This function displays the structure information about one or more expressions, including the expression type and value. The array recursively expands the value and displays its structure through indentation.
Tip: to prevent the program from directly outputting the results to the browser, you can use the output-control function to capture the output of this function, and save them to a variable of the string type, for example.
We can compare var_dump () and print_r ().
The instance code is as follows:
-
-
- $ A = array (1, 2, array ("a", "B", "c "));
- Var_dump ($ );
- /* Output:
- Array (3 ){
- [0] =>
- Int (1)
- [1] =>
- Int (2)
- [2] =>
- Array (3 ){
- [0] =>
- String (1) ""
- [1] =>
- String (1) "B"
- [2] =>
- String (1) "c"
- }
- }
- */
- $ B = 3.1;
- $ C = TRUE;
- Var_dump ($ B, $ c );
- /* Output:
- Float (3.1)
- Bool (true)
- */
- ?>
-