PHP Beginner's Introduction to Output Functions

What is the output in php? What's the difference between these?

1.echo

echo is a language construct, that is, a keyword, not a real function, so it cannot be used as an expression. Partially used. You don't need to add parentheses when using it, you can just add it. Only basic types are supported, except for Boolean types. When echo true, it displays 1, and when echo false, nothing happens. Echo cannot output array type

array, output array For Boolean type, true outputs 1 false outputs nothing

2. print()

Only one string can be output, and the syntax of comma-separated multiple display variables is not supported. Print can output array type data,

"; print($arr); echo "
"; print($arr[1]); ?>

Note: $a is a string, which can be output using print$arr is an array, which cannot be output

$ arr is also an array. When using print to output, I added a subscript and output the first digit

3.print_r()

Okay Print out the value of complex type variables (such as arrays, objects)

 'apple', 'b' => 'banana', 'c' => array ('x','y','z')); print_r($arr); ?>

Note: If the variable is string, integer and float, its value will be output directly. If the variable is an array, a formatted value will be output. The following array is easy to read,

4.printf();

Syntax: printf(format,arg1,arg2,arg++)

The format parameter is the conversion format, starting with the percent sign ("%") and ending with the conversion character. The following are possible format values:
* %% – Returns the percent sign
* %b – Binary number
* %c – Character according to the ASCII value
* %d – Signed decimal number
* %e – Continuous counting method (such as 1.5e+3)
* %u – Unsigned decimal number
* %f – Floating point number (local settings aware)
* %F – Float Points (not local settings aware)
* %o – Octal number
* %s – String
* %x – Hexadecimal number (lowercase letters)
* %X – Sixteen Parameters such as base numbers (uppercase letters)
arg1, arg2, arg++, etc. will be inserted into the main string at the percent sign (%) symbol. The function is executed step by step, at the first % sign, arg1 is inserted, at the second % sign, arg2 is inserted, and so on. If there are more % symbols than arg arguments, you must use placeholders. Placeholders are inserted after the % sign and consist of numbers and "\$". You can use numbers to specify the displayed parameters

Note: This is still relatively rarely used in php

5.var_dump function

Function: Output the content, type of the variable or the content, type, and length of the string.Commonly used for debugging.

Note: The type of output $b is a string type

Continuing Learning
||
"; echo true; echo false; ?>
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!