{"id":15237,"date":"2020-06-20T13:06:54","date_gmt":"2020-06-20T13:06:54","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=15237"},"modified":"2022-04-28T09:15:24","modified_gmt":"2022-04-28T09:15:24","slug":"difference-between-echo-and-print-in-php","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/difference-between-echo-and-print-in-php\/","title":{"rendered":"Difference Between echo and print in PHP"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Echo vs. Print<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>PHP echo and print both are PHP Statements<\/li><li>Both are used to displaying the output in PHP.<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">What is echo<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>The echo is a statement i.e used to display the output. it can be used with parentheses echo or without parentheses echo.<\/li><li>echo can pass multiple strings separated as (,).<\/li><li>echo does,t return any value.<\/li><li>echo is faster than print.<\/li><li>It can accept multiple expressions.<\/li><\/ul>\n\n\n\n<p><strong>Echo Example-&gt;<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/2052cf1668535644af6623e16c2a063a.js\"><\/script>\n\n\n\n<p><strong>For Example (pass multiple argument)<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/cda7a8942c897dc6bf3a20ab9999a408.js\"><\/script>\n\n\n\n<p>Now we want to print all three variable values together. all variables names are define inside the echo statement separated by comm or dot(,or.) it will show the output.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is Print<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>It is also a statement which is used to display the output and used with the parentheses print() or without the parentheses print.<\/li><li>It cannot accept multiple expressions.<\/li><li>It is slower than echo as it return a value.<\/li><li>It cannot pass multiple argument<\/li><li>It always return the value 1.<\/li><\/ul>\n\n\n\n<p><strong>Example-&gt;<\/strong> now we want to print the name. we simply define $name inside print statement with or without parentheses.<br>It will show the output: &#8220;dharmu&#8221;.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/6ddd90bd91028dd06688a3df9eb17040.js\"><\/script>\n\n\n\n<p><strong>For Example (pass multiple argument)<\/strong><\/p>\n\n\n\n<p>Declare three variable $name, $profile, $age and hold the value (&#8220;dharmu,&#8221;php developer&#8221;,25).<br>Now check whether it will allow executing multiple arguments.<br>Pass three variables inside the print statement separated by a comma. As we run this program it shows error.<br>It means multiple arguments are not allowed in print.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/0c7789adf7a8b847f63566b3f60bfead.js\"><\/script>\n\n\n\n<p><strong>Output: Parse error: syntax error<\/strong><\/p>\n\n\n\n<p><strong>For Example (Check return type)<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/7836fda2f110737439c34d00c09c7a98.js\"><\/script>\n\n\n\n<p><strong>Output:<\/strong><br>dharmu<br>In the above example<br>declare a variable $name hold value=&#8221;dharmu&#8221;.now we check the return type of print.<br>So (Print $name) is store in a variable ($ret).<br>it will show $name value with return type=1.<\/p>\n\n\n\n<p>These other Difference Between echo and print in PHP<\/p>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_94315\"><iframe loading=\"lazy\"  id=\"_ytid_38941\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_94315\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Echo vs. Print PHP echo and print both are PHP Statements Both are used to displaying the output in PHP. What is echo The echo is a statement i.e used&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5150],"tags":[4225,5839],"class_list":["post-15237","post","type-post","status-publish","format-standard","hentry","category-php","tag-echo","tag-print"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/15237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=15237"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/15237\/revisions"}],"predecessor-version":[{"id":24744,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/15237\/revisions\/24744"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=15237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=15237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=15237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}