PHP Echo and Print statements

Source: Internet
Author: User
Tags echo command learn php php print

Echo and Print differences:
    • echo-can output one or more strings
    • Print-allows only one character to be output, with a total return value of 1
    • The echo output is faster than print speed, ECHO has no return value, and print has a return value of 1.
PHP Echo Statement

Echo is a language structure that can be used with parentheses or without parentheses: Echo or Echo ()

echo Command output string:

<?phpecho "

echo Output variables and strings:

<?php$txt1= "Learning php", $txt 2= "runoob.com", $cars =array ("Volvo", "BMW", "Toyota"); echo $txt 1;echo "<br>", echo "in $txt 2 to learn PHP"; echo "<br>" echo "The brand of my car is {$cars [0]}";? >
PHP Print Statement

Print is the same, and can be used without parentheses: print or print ();

Print command output string:

<?phpprint "

Print output variables and strings:

<?php$txt1= "Learning php", $txt 2= "runoob.com", $cars =array ("Volvo", "BMW", "Toyota"); Print $txt 1;print "<br>";p rint "in $txt 2 to learn PHP";p rint "<br>";p rint "the brand of my car is {$cars [0]}";? >
Common output statements

Echo (): Multiple values can be output at one time, and multiple values are separated by commas. Echo is not a true function, the echo structure is (language construct) and cannot be used as part of an expression.

Print (): printing () prints a value (its arguments) and returns True if the string succeeds, or False if it is successfully displayed.

Print_r (): You can simply print the string and the number, and the array is displayed with the enclosed key and the list of merit, beginning with an array. However, the result of Print_r () output Boolean and null is meaningless because it is all printed "\ n". Therefore, using the Var_dump () function is more suitable for debugging.

var_dump (): determine the type and length of a variable, and output the value of the variable, if the variable has a value to lose is a variable and return data type. This function displays structure information about one or more expressions, including the type and value of the expression. The array recursively expands the value and displays its structure by indentation.

 

PHP Echo and Print statements

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.