Home > Backend Development > PHP Problem > How to output the php program?

How to output the php program?

青灯夜游
Release: 2023-02-26 10:58:01
Original
3354 people have browsed it

How to output the php program? In PHP, you can use echo statement, print statement, printf(), print_r(), var_dump() to achieve output. Let's take a look at these output methods, hoping to help everyone.

How to output the php program?

echo statement

echo is a language structure, with or without parentheses Use of brackets: echo or echo() can be used for output. It is the most commonly used output statement. Example:

<?php
echo "PHP中文网";
echo ("m.sbmmt.com");
?>
Copy after login

Output:

How to output the php program?

Description: In normal times, the output of echo or echo() is the same, only when multiple parameters are passed to Echo statement, when outputting, using parentheses will generate a parsing error.

print statement

The print statement can also achieve output and has a return value. It returns 1 on success and 0 on failure; therefore it can be used in expressions.

<?php
print "hello ";
print ("world!");
?>
Copy after login

Note: The print statement can also be used with or without parentheses, there is not much difference.

Output:

How to output the php program?

printf()

The printf() function can also be used To achieve output, you can output ordinary strings and formatted output. Example:

<?php
$a=20;
printf("输出:");
printf("a=%f",$a);
?>
Copy after login

Output:

How to output the php program?

print_r()

print_r() Functions are used to output variables and can display information about this variable in a format that is easy for humans to read.

<?php
$a = array (&#39;a&#39; => &#39;apple&#39;, &#39;b&#39; => &#39;banana&#39;, &#39;c&#39; => array (&#39;x&#39;,&#39;y&#39;,&#39;z&#39;));
echo "<pre class="brush:php;toolbar:false">";
print_r ($a);
echo "
Copy after login
"; ?>

Output:

How to output the php program?

var_dump()

var_dump() function For output variables, you can display the structured information of the variable, such as type and value.

<?php
$var_name=array(99,&#39;w3resource&#39;,67899.99, array(&#39;X&#39;,&#39;Y&#39;,1));
var_dump($var_name);
?>
Copy after login

Output:

How to output the php program?

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of How to output the php program?. 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