• PHP Video Tutorials

PHP - var_export() Function


Advertisements

Definition and Usage

The function var_export() outputs or returns a parsable string representation of a variable. It is similar to var_dump() with one exception, the returned representation is valid PHP code.

Syntax

string|null var_export ( mixed $value , bool $return = false )

Parameters

Sr.No Parameter Description
1

value

Mandatory.The variable you want to export.

2

return

Optional. If used and set to true, var_export() will return the variable representation instead of outputting it.

Return Values

This function returns the variable representation when the return parameter is set to true. Otherwise, this function will return null.

Dependencies

PHP 4.2 and above

Example

Following example demonstrates use of var_export():

  <?php
  $a = "Welcome TutorialsPoint!";
  var_export($a);
  echo "<br>";
  $b = array(2,'hello',22.99, array('a','b',2));
  var_export($b);
  echo "<br>";

  // Create a class
  class tutorialsPoint {
      public $tp_name =
            "Welcome to TutorialsPoint";
  }

  // Create the class name alias
  class_alias('tutorialsPoint', 'TP');

  $obj1 = new tutorialsPoint();
  var_export($obj1);
  ?>

Output

This will produce following result −

  'Welcome TutorialsPoint!'
  array ( 0 => 2, 1 => 'hello', 2 => 22.99, 3 => array ( 0 => 'a', 1 => 'b', 2 => 2, ), )
  tutorialsPoint::__set_state(array( 'tp_name' => 'Welcome to TutorialsPoint', ))

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements