

{"id":135787,"date":"2024-07-17T12:24:28","date_gmt":"2024-07-17T06:54:28","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=135787"},"modified":"2024-07-17T12:24:28","modified_gmt":"2024-07-17T06:54:28","slug":"call-by-reference-and-call-by-value-in-php","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/","title":{"rendered":"Difference Between Call by Reference and Call by Value in PHP"},"content":{"rendered":"<h3>Program 1<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;html&gt;\r\n&lt;head&gt;&lt;title&gt;Demo&lt;\/title&gt;&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;center&gt;\r\n    &lt;?php\r\n        function swap(&amp;$a,&amp;$b)   \/\/call by reference \r\n       {\r\n              $c=$a;\r\n              $a=$b;\r\n              $b=$c;\r\n       }\r\n\r\n    \r\n    \r\n    $a=500;\r\n    $b=300;\r\n    echo \"Value is : \".$a;\r\n    \r\n    \/\/ echo \"&lt;br&gt;Before Swaping: \".$a.\"  \".$b;\r\n    \/\/ swap($a,$b);\r\n    \/\/ echo \"&lt;br&gt;After Swaping: \".$a.\"  \".$b;\r\n\r\n\r\n        \/\/ $a=500;\r\n        \/\/ $b=&amp;$a;\r\n        \/\/ echo \"a=\".$a.\"&lt;br&gt;\";\r\n        \/\/ echo \"b=\".$b.\"&lt;br&gt;\";\r\n        \/\/ $b=1500;\r\n        \/\/ echo \"a=\".$a.\"&lt;br&gt;\";\r\n        \/\/ echo \"b=\".$b.\"&lt;br&gt;\";\r\n        \/\/ $a=$a+1000;\r\n        \/\/ echo \"a=\".$a.\"&lt;br&gt;\";\r\n        \/\/ echo \"b=\".$b.\"&lt;br&gt;\";\r\n\r\n\r\n?&gt;\r\n&lt;\/center&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h3>Program 2<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;html&gt;\r\n&lt;head&gt;&lt;title&gt;Demo clone&lt;\/title&gt;&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;center&gt;\r\n    &lt;?php\r\n       class employee\r\n       {\r\n           public $name;\r\n           public $department;\r\n          public function __construct($ename) \r\n          {\r\n                 $this-&gt;name=$ename;\r\n          }\r\n       }\r\n\r\n$e1=new employee(\"Vishal Verma\");\r\n\r\n$e2=clone $e1;\r\necho \"e1=\".$e1-&gt;name.\"&lt;br&gt;\";\r\necho \"e2=\".$e2-&gt;name.\"&lt;br&gt;\";\r\n\r\n$e2-&gt;name=\"Ashok Gupta\";\r\necho \"&lt;br&gt;----After Change Name---------&lt;br&gt;\";\r\necho \"e1=\".$e1-&gt;name.\"&lt;br&gt;\";\r\necho \"e2=\".$e2-&gt;name.\"&lt;br&gt;\";\r\n?&gt;\r\n&lt;\/center&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Program 1 &lt;html&gt; &lt;head&gt;&lt;title&gt;Demo&lt;\/title&gt;&lt;\/head&gt; &lt;body&gt; &lt;center&gt; &lt;?php function swap(&amp;$a,&amp;$b) \/\/call by reference { $c=$a; $a=$b; $b=$c; } $a=500; $b=300; echo &#8220;Value is : &#8220;.$a; \/\/ echo &#8220;&lt;br&gt;Before Swaping: &#8220;.$a.&#8221; &#8220;.$b; \/\/ swap($a,$b); \/\/ echo&#46;&#46;&#46;<\/p>\n","protected":false},"author":86671,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31445],"tags":[32662,32660,32661,21772,32390,32385,32332,32333],"class_list":["post-135787","post","type-post","status-publish","format-standard","hentry","category-php-tutorials","tag-call-by-reference-and-call-by-value","tag-call-by-reference-and-call-by-value-in-php","tag-difference-between-call-by-reference-and-call-by-value-in-php","tag-php","tag-php-call-by-reference","tag-php-call-by-value","tag-php-practical","tag-php-program"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Difference Between Call by Reference and Call by Value in PHP - DataFlair<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Difference Between Call by Reference and Call by Value in PHP - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Program 1 &lt;html&gt; &lt;head&gt;&lt;title&gt;Demo&lt;\/title&gt;&lt;\/head&gt; &lt;body&gt; &lt;center&gt; &lt;?php function swap(&amp;$a,&amp;$b) \/\/call by reference { $c=$a; $a=$b; $b=$c; } $a=500; $b=300; echo &quot;Value is : &quot;.$a; \/\/ echo &quot;&lt;br&gt;Before Swaping: &quot;.$a.&quot; &quot;.$b; \/\/ swap($a,$b); \/\/ echo&#046;&#046;&#046;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-17T06:54:28+00:00\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Difference Between Call by Reference and Call by Value in PHP - DataFlair","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/","og_locale":"en_US","og_type":"article","og_title":"Difference Between Call by Reference and Call by Value in PHP - DataFlair","og_description":"Program 1 &lt;html&gt; &lt;head&gt;&lt;title&gt;Demo&lt;\/title&gt;&lt;\/head&gt; &lt;body&gt; &lt;center&gt; &lt;?php function swap(&amp;$a,&amp;$b) \/\/call by reference { $c=$a; $a=$b; $b=$c; } $a=500; $b=300; echo \"Value is : \".$a; \/\/ echo \"&lt;br&gt;Before Swaping: \".$a.\" \".$b; \/\/ swap($a,$b); \/\/ echo&#46;&#46;&#46;","og_url":"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2024-07-17T06:54:28+00:00","author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/0e594f928e31fc96628ac40f6ae74f49"},"headline":"Difference Between Call by Reference and Call by Value in PHP","datePublished":"2024-07-17T06:54:28+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/"},"wordCount":14,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"keywords":["call by reference and call by value","call by reference and call by value in php","difference between call by reference and call by value in php","PHP","php call by reference","php call by value","php practical","php program"],"articleSection":["PHP Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/","url":"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/","name":"Difference Between Call by Reference and Call by Value in PHP - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"datePublished":"2024-07-17T06:54:28+00:00","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/call-by-reference-and-call-by-value-in-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"PHP Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/php-tutorials\/"},{"@type":"ListItem","position":3,"name":"Difference Between Call by Reference and Call by Value in PHP"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/0e594f928e31fc96628ac40f6ae74f49","name":"TechVidvan Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","caption":"TechVidvan Team"},"description":"TechVidvan Team provides high-quality content &amp; courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.","url":"https:\/\/data-flair.training\/blogs\/author\/test001\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/135787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/86671"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=135787"}],"version-history":[{"count":3,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/135787\/revisions"}],"predecessor-version":[{"id":142820,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/135787\/revisions\/142820"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=135787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=135787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=135787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}