Usage of var_export and var_dump

Source: Internet
Author: User
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:

  1. $ Res = yblog_mspconfiginit ("ratings ");
  2. Var_dump ($ res );
  3. Var_export ($ res); result:
  4. Resource (1) of type (yahoo_yblog)
  5. NULL, for example:
  6. $ Res = fopen('status.html ', 'r ');
  7. Var_dump ($ res );
  8. Var_export ($ res); result:
  9. Resource (2) of type (stream)
  10. NULL

The instance code is as follows:

  1. // Php var_export read/write instance class
  2. Class user {
  3. Var $ filepath;
  4. Function __()
  5. {
  6. $ This-> filepath = "d:/www.111cn.net/group /";
  7. }
  8. Function cache (){
  9. $ Array = $ this-> db-> select ('select group_id, group_name from group', 'hashmap ');
  10. $ Fp = fopen ($ this-> filepath, 'w ');
  11. Fputs ($ fp ,' ');
  12. Fclose ($ fp );
  13. }
  14. Function getVar_export ($ value ){
  15. $ Array = require ($ this-> filepath );
  16. Foreach ($ array as $ key => $ v ){
  17. If ($ key = $ value ){
  18. $ Selected = 'current option ';
  19. } Else {
  20. $ Selected = '';
  21. }
  22. $ Html. =' '. $ V .'';
  23. }
  24.  
  25. Return $ html;
  26. }
  27. }
  28. // Use the instance method
  29. $ G = new user ();
  30. If (intval ($ _ GET ['iscreate'])
  31. {
  32. $ G-> cache ();
  33. }
  34. Else
  35. {
  36. $ G-> getVar_export ('vv ');
  37. }
  38. // Original site www.111cn.net reprinted to indicate the source
  39. ?>

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:  

  1.  
  2.   
  3. $ A = array (1, 2, array ("a", "B", "c "));
  4. Var_dump ($ );
  5. /* Output:
  6. Array (3 ){
  7. [0] =>
  8. Int (1)
  9. [1] =>
  10. Int (2)
  11. [2] =>
  12. Array (3 ){
  13. [0] =>
  14. String (1) ""
  15. [1] =>
  16. String (1) "B"
  17. [2] =>
  18. String (1) "c"
  19. }
  20. }
  21. */
  22. $ B = 3.1;
  23. $ C = TRUE;
  24. Var_dump ($ B, $ c );
  25. /* Output:
  26. Float (3.1)
  27. Bool (true)
  28. */
  29. ?>
  30.    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.