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

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 565
    Comment on it

    The echo and print are similar ones as they are not a functions they are the language constructs.

    echo

    The echo as a language construct it outputs one or more strings. The echo has a void data type.As it is a construct and not a function so it wont require parenthesis.

    example :

    <?php echo "Hello world"; ?> 
    

    print

    The print is a language construct, The print is actually a function with return value 1. It can be used in expression.

    example :

    <?php print("Hello world"); ?> 
    

    Note: echo is much faster than print.

    print_r

    It gives the output in a way which is much easier to be readable by humans. It accepts strings but also arrays and format them in a readable format.It is used mostly in debugging purposes.

    example:

    <?php
    $day = array (m => monday, t' => tuesday, w => 'wednesday');
    print&#95;r ($day);
    ?>
    

 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: