PHP Echo / Print In Hindi

📔 : PHP 🔗

PHP में हम value को print कराने के लिए echo() function का Use करते है , echo के बाद आप Parenthesis use कर भी सकते हैं और न भी करते हैं तो भी कोई problem नहीं है।

Example -

File : test.php

Copy Fullscreen Close Fullscreen
<?php 
  $name = "Rahul Kumar";
echo $name."<br>";
echo($name); ?>
Output
Rahul Kumar
Rahul Kumar

Example में आप देख सकते हैं की value को हम दोनों तरह से Print करा सकते हैं। इसके अलावा PHP में print() function भी है जिसे हम value को print करने में ले सकते है।

Note - Example में '<br>' का use line break के लिए किया गया है और dot (.) का use String Concatenation के लिए।

File : test2.php

Copy
<?php 
  $name = "Rahul Kumar";
print$name."<br>";
print($name); ?>
Output
Rahul Kumar
Rahul Kumar

Difference Between Echo() and Print()

सबसे बड़ा difference यह है कि echo() function किसी value को print करने के बाद कुछ return नहीं करता जबकि print() function value को print करने के बाद 1 return करता है।

File : test3.php

Copy Fullscreen Close Fullscreen
<?php 
   $name="Rahul";
echo print($name)."<br>"; ?>
Output
Rahul
1

Note - print() function हमेशा ही 1 return करता हो चाहे value print हो या न हो , variable Define किया गया हो या न किया गया हो|

File : test4.php

Copy Fullscreen Close Fullscreen
<?php 
  $name;
echo print($name);
echo print($nsame); ?>
Output
Notice: Undefined variable: name in C:\xampp\htdocs\test\test.php on line 3
1
Notice: Undefined variable: nsame in C:\xampp\htdocs\test\test.php on line 4
1

ऊपर दिए गए Example में आप देख सकते हैं एक variable को सिर्फ initialize किया गया है कोई value assign नहीं की गयी जबकि दूसरी लाइन में non-define variable print कराने की कोशिश की but error आने के बाद भी print() function ने 1 return किया।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers