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.
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"); ?>
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()
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); ?>
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:
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!