Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Diffrence between echo and print in PHP

    • 0
    • 2
    • 2
    • 2
    • 0
    • 0
    • 0
    • 0
    • 157
    Comment on it

    Hello Readers!

    You might have heard these "echo" and "print" statement in PHP many times. So here we will understand now what is the exact difference of these two words.

    Both echo and print are used to output a statement. Below are the some basic difference of these two PHP functions.

    echo:

    1-> echo doesn't return any value.

    2->echo is faster than print.

    3->Using echo we can pass multiple strings separated as (,).

    Here's the code to understand the echo.

    <?php
    $name = "Shashank ";
    $profile = "PHP Developer";
    $age = 24;
    echo $name , $profile , $age, " years old";
    ?>
    

    Output: Shashank PHP Developer24 years old

    Example 2:(check return type)

    <?php
    $name = "Shashank ";
    $return =  echo $name;
    ?>
    

    Here we can see that we have stored echo $name in some variable then according to definition of echo it will give error.

    Output: Parse error: syntax error, unexpected T_ECHO

    Now we will understand how print statement works.

    print:

    1->using print can doesnt pass multiple argument.

    2->it is slower than echo.

    3->print always return 1.

    Here's the code to understand the print statment:

    <?php
    $name="Shashank";
    print $name;
     //or
    print ($name);
     ?>
    

    Output:Shashank

    Example 2: (check return type)

    Here we can see print $name is stored in $return variable. And as per the definition of print it will always return 1.

    Output:Shashank

    Happy Coding!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: