PHP echo
The function of PHP echo is to output a string ( String ) and can output at least one or more strings at a time . Often people mistake echo for a function. In fact, echo is not a PHP function, but a language structure (language construct), so you don’t necessarily need to use parentheses when using PHP echo, you can directly use single quotes, double quotes or even directly output the result of string variables , depending on the item to be echoed.
PHP echo basic syntax
echo( string ); echo "string"; echo'string'; echo $string;
As mentioned in the first paragraph, PHP echo is not a function, so it can be used just like a function, but it does not have to use parentheses like a function. It is worth noting that if the output is a variable , it cannot Use single quotation marks, otherwise PHP will directly output the content of single quotation marks as a string instead of outputting the content of the variable .
PHP echo example 1: output string
echo'Today's weather is very good<br>';
echo "Today's weather is very good<br>";
echo ('Today's weather is very good<br>');
echo Today's weather is very good;
?>

echo string, is the simplest. In the example, single quotes, double quotes, parentheses and nothing are used, and the results can be echoed smoothly.
PHP echo example two, output variables
$string='PHP echo test.';
echo $string;
?>
In example two, use echo to directly output a variable $string, you can also write: echo "$string";
PHP echo example three, output array
$NewArray=array('A','B','C');
echo $NewArray[0].'-';
echo $NewArray[1].'-';
echo $NewArray[2];
?>
PHP echo This language structure function is used to output strings , but it can also be used to output PHP Array array values. For the case where only a single array key value is output, using PHP echo is quite simple and easy The method, like echo $NewArray[0] in the example, represents the first key value of the output array, and so on, followed by the following.'-' is only the "-" symbol used to output HTML to output the result The three English letters of "are just strung together. If you want to output the entire array, the PHP print_r function is recommended .
Post a Comment
0 Comments