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. I hope it will be helpful to everyone.
echo statement
echo is a language construct that can be used with or without parentheses: Echo or echo() can be used for output, and it is the most commonly used output statement. Example:
<?php echo "PHP中文网"; echo ("www.php.cn"); ?>
Output:
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!"); ?>
Note: The print statement can also be used with or without parentheses, there is not much difference.
Output:
printf() function
printf() function also Output can be achieved, ordinary strings can be output, and output can also be formatted. Example:
<?php $a=20; printf("输出:"); printf("a=%f",$a); ?>
Output:
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 ('a' => 'apple', 'b' => 'banana', 'c' => array ('x','y','z')); echo "<pre class="brush:php;toolbar:false">"; print_r ($a); echo "
Output:
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,'w3resource',67899.99, array('X','Y',1)); var_dump($var_name); ?>
Output:
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.
The above is the detailed content of How to achieve output in PHP? What are the output methods of PHP?. For more information, please follow other related articles on the PHP Chinese website!