Var_export ()

Source: Internet
Author: User

returns the structure information about the variable passed to the function

Var_exportThe () function returns the structure information about the variable passed to the function, andVar_dump() Similarly, the difference is that the representation of its return is a valid PHP code. Var_export must return a valid PHP code, that is, the code returned by Var_export can be directly assigned to a variable as PHP code. And this variable gets the same value as the Var_export type. Let's look at a simple example:1<?PHP2 3$arr=Array(1, 2,Array("Apple", "banana", "orange" )); 4Var_export($arr ); 5 6?>Program output:01Array (0 = 1,03 1 = 2,04 2 =>05Array (0 = ' Apple ', 1 = ' banana ', 2 = ' orange ', 09  ), 10Note that the above output is a valid PHP code. If Var_dump () is used, the output is:01Array(3) {02  [0]=>03Int (1)04  [1]=>05Int (2)06  [2]=>07Array(3) {08    [0]=>09string(5) "Apple" 10    [1]=>11string(6) "Banana" 12    [2]=>13string(6) "Orange" 14  }15You can set the second argument of a function toTRUE, which returns the representation of the variable. 1<?PHP2 3$v= ' Nowamagic '; 4$rs=Var_export($v,TRUE ); 5 6Echo $rs;7?>program Run Result:1 ' nowamagic 'Note two points:Var_export() retains the structured form of storing data.but in particular, remember that the type of the variable value at this point is already a string ($var), you can no longer remove the value in the array. In the Phpcms source code, you can see that many of the configuration parameters are recorded in an array, including their channels, content, and so on. 01functionCache_write ($file,$string,$type= ' array ') 02{ 03if(Is_array($string)) 04    { 05$type=Strtolower($type); 06if($type= = ' array ') 07        { 08$string= "<?php\n return".Var_export($string,TRUE).";\ N?> "; 09        } 10ElseIf($type= = ' constant ') 11        { 12$data= ' '; 13foreach($string  as $key=$value)$data. = "define ('").Strtoupper($key)."‘,‘". 14addslashes($value)."‘);\ N; 15$string= "<?php\n".$data." \n?> "; 16        } 17    } 18$strlen=file_put_contents(Phpcms_cachedir.$file,$string); 19chmod(Phpcms_cachedir.$file, 0777); 20return $strlen; 21st} 

Var_export ()

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.