PHP var_export() Function In Hindi | var_export() In PHP In Hindi

Blogs ❯❯ PHP

Image could not load

PHP var_export()

Normally PHP में जब हम variable को print / echo कराते हैं तो उसकी value print होती है। लेकिन अगर आप उस variable में stored value को actual PHP form में देखना चाहते हैं तो var_export() function का use कर सकते हैं।

PHP var_export()

var_export() function दिए गए variable की structured information return करता है जो कि actual PHP code होता है। यह var_dump() function के जैसे ही है बस difference इतना है कि var_dump() variable में stored value के बारे में information देता है जो PHP code नहीं होता है।

PHP var_export() Syntax
 var_export(mixed $value, bool $return = false): ?string
  • $value | required : यह वो variable है जिसे export करना है।

  • $return | optional : by default false set होता है , लेकिन अगर आपने true set किया तो यह सिर्फ variable को represent करेगा मतलब फिर आपको echo use करना पड़ेगा। और false के साथ echo के बिना output print करेगा।

PHP var_export() example

$a = array (1, 2, array ("a", "b", "c")); var_export($a);

output

array (
  0 => 1,
  1 => 2,
  2 => 
  array (
    0 => 'a',
    1 => 'b',
    2 => 'c',
  ),
)

अब अगर आप true pass करेंगे तो output देखने के लिए आपको echo use करना पड़ेगा। हालाँकि output same रहेगा।

$a = array (1, 2, array ("a", "b", "c")); echo var_export($a, true);

PHP var_export() example

इसी तरह से stdClass Class को भी export कर सकते हैं।

$obj = new stdClass; $obj->title = 'Learn programming in hindi'; $obj->website = 'https://learnhindituts.com'; var_export($obj);

Output

(object) array(
   'title' => 'Learn programming in hindi',
   'website' => 'https://learnhindituts.com',
)

PHP var_export() example

और कुछ इसी तरह से normal Class object को भी export कर सकते हैं।

class A { public $title; public $website; } $a = new A(); $a->title = "Learn programming in hindi"; $a->website = "https://learnhindituts.com"; var_export($a);

Output

\A::__set_state(array(
   'title' => 'Learn programming in hindi',
   'website' => 'https://learnhindituts.com',
))

I hope , अब आप PHP में var_export() function के बारे में अच्छे से समझ गए होंगे ।

Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook