Var_export function usage, var_export usage _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
How to use the var_export function. The var_export function is used. the var_export usage method var_export () function returns the structure information about the variables passed to the function, which is similar to var_dump, the difference is the usage of the var_export function returned by var_export.

The var_export () function returns the structure information about the variables passed to the function. it is similar to var_dump (). The difference is that the returned representation is a valid PHP code. 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. This variable gets the same type value as var_export. Let's look at the following simple example:

 

Program output:

array (  0 => 1,  1 => 2,  2 =>   array (    0 => 'apple',    1 => 'banana',    2 => 'orange',  ),)

Note that the above output is a valid PHP code. If var_dump () is used, the output is:

array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  array(3) {    [0]=>    string(5) "apple"    [1]=>    string(6) "banana"    [2]=>    string(6) "orange"  }}

You can set the second parameter of the function to TRUE to return the expression of the variable.

 

Program running result:

'nowamagic'

Note:

  • Var_export () keeps structured data.
  • However, remember that the variable value type is already a string ($ var). you cannot retrieve the value from the array.

In the source code of PHPCMS, we can see that many configuration parameters are recorded in arrays, including their channels and contents.

function cache_write($file, $string, $type = 'array')  {      if(is_array($string))      {          $type = strtolower($type);          if($type == 'array')          {              $string = "
 ";          }          elseif($type == 'constant')          {              $data='';              foreach($string as $key => $value) $data .= "define('".strtoupper($key)."','".  addslashes($value)."');\n";              $string = "
 ";          }      }      $strlen = file_put_contents(PHPCMS_CACHEDIR.$file, $string);      chmod(PHPCMS_CACHEDIR.$file, 0777);      return $strlen;  }  
Additional reading

The topic list of this article is as follows:

The var_export () function returns the structure information about the variables passed to the function. it is similar to var_dump (), but the difference is that it returns...

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.