No results found for the specified position. What is the difference between echo and pr... PHP Basic Concepts Mock Interview

MockQuestions

PHP Basic Concepts Mock Interview

Question 2 of 21 for our PHP Basic Concepts Mock Interview

Get More Information About Our PHP Basic Concepts Interview Questions

Question 2 of 21

What is the difference between echo and print in php?

In PHP both echo and print are used to output data to a browser.

echo just outputs the value in the browser's screen while print outputs and also returns 1 when we use it.

Also, we can output multiple values using echo separated by commas.

<?php 

    echo "123", " 456", " some other value"; // here, we're printing multiple values using commas
    
    echo "<br />";

    $the_return_value = print "user"; // we can also do print()
    
    echo "<Br />";
    
    echo $the_return_value; // this is the 

?>

In the above coding example, we can see that we've used echo to print out multiple values just by separating with commas but print can't do that and also print returns 1 when we use print to print something.

Technically, echo is faster than print because it doesn't return any value.

Most developers do not have a preference as the difference between echo and print are small.

Written by on May 4th, 2021

Next Question

How to Answer: What is the difference between echo and print in php?

Advice and answer examples written specifically for a PHP Basic Concepts job interview.

  • 2. What is the difference between echo and print in php?

      In PHP both echo and print are used to output data to a browser.

      echo just outputs the value in the browser's screen while print outputs and also returns 1 when we use it.

      Also, we can output multiple values using echo separated by commas.

      <?php 
      
          echo "123", " 456", " some other value"; // here, we're printing multiple values using commas
          
          echo "<br />";
      
          $the_return_value = print "user"; // we can also do print()
          
          echo "<Br />";
          
          echo $the_return_value; // this is the 
      
      ?>

      In the above coding example, we can see that we've used echo to print out multiple values just by separating with commas but print can't do that and also print returns 1 when we use print to print something.

      Technically, echo is faster than print because it doesn't return any value.

      Most developers do not have a preference as the difference between echo and print are small.

      Written by Sujal khatiwada on May 4th, 2021