Detailed explanation of the usage of php echo

藏色散人
Release: 2023-03-04 09:28:02
Original
3265 people have browsed it

php echo is a language structure rather than a function. The function of echo is to output a string. It is a language structure with a very high usage rate. The usage syntax is such as [echo 'Welcome';]. The output result is [Welcome].

Detailed explanation of the usage of php echo

Recommended: "PHP Video Tutorial"

PHP echo is strictly a language construct (language construct) Instead of a function, the function of echo is to output strings. It is a language structure with a very high usage rate, especially in systems that do not use template mode. Similar to echo, there is print. The difference between the two is not big. Normally, just use echo. In addition, since echo is not a function, it is more flexible in use. Here are several examples of different echo output methods.

PHP echo example 1. Output a single string

<?php
 echo &#39;欢迎光临&#39;;
?>
Copy after login

The above example output

欢迎光临
Copy after login

This is the most basic PHP echo application. Put it directly in single quotation marks ('') or double quotation marks (""), and connect it after echo, which means that echo will output the string in the quotation marks to the screen. You can also use parentheses to wrap the string. If To output multiple strings at one time, you need to use a connection trick. Please see Example 2.

PHP echo example two, output a combination of multiple strings

<?php
 echo &#39;您好:&#39;.&#39;欢迎光临&#39;;
?>
Copy after login

The above example output

您好:欢迎光临
Copy after login

In example two, we will The strings "Hello:" and "Welcome" are strung together through PHP's string connection symbol (.), allowing echo to output two strings at a time. The connection symbol will not appear in the output result, but a complete string.

PHP echo example three, output array elements

<?php
$NewArray=array( &#39;苹果&#39; , &#39;香蕉&#39; , &#39;水梨&#39; );
echo $NewArray[1];
?>
Copy after login

The above example output

香蕉
Copy after login

Usually to output the array elements of the entire PHP Array, print_r will be used To output, if you just want to output a single independent array value, you can use echo to complete it. For example, in the example, we only need to output bananas. It is very convenient to use echo to output. The designer or system needs to clearly know the array to be echoed. What is the key? Usually the designer will specify the array key before echoing.

The above is the detailed content of Detailed explanation of the usage of php echo. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template