Speaking of output, I have to mention printing in php. First of all, it is the most commonly used echo. echo: outputs one or more strings; print: is the same as echo, but the speed is slower than echo. Print_r: prints easy-to-understand information about the variable. If string, integer, or float is provided, the variable itself is printed. If array
Speaking of output, I have to mention printing in php. First of all, it is the most commonly used echo. echo: outputs one or more strings; print: is the same as echo, but the speed is slower than echo. Print_r: prints easy-to-understand information about the variable. If string, integer, or float is provided, the variable itself is printed. If array
Speaking of output, I have to mention printing in php.
Echo: outputs one or more strings;
Print: Same as echo, but slower than echo.
Print_r:
Print easy-to-understand information about variables. If string, integer, or float is provided, the variable value itself is printed. If array is provided, keys and elements are displayed in a certain format. Objects are similar to arrays. Remember, print_r () will move the array pointer to the last edge. Use reset () to bring the pointer back to the beginning.
Var_export: similar to print_r and var_dump, but rarely used.
Var_dump:
This function displays the structure information about one or more expressions, including the expression type and value. The array recursively expands the value and displays its structure through indentation.
Differences between var_dump and print_r:
Var_dump returns the expression type and value while print_r returns only the result, which is easier to read than using var_dump in debugging code.
The differences between print_r (), var_export (), and var_dump () can be found below:
Eg: Two-dimensional array output:
$ Arr = array ('A' => 'A', 'B' => 'bbb ', 'c' => 'ccc '),
Array ('A' => 'ddd ',' B '=> 'Eee', 'c' => 'fff '),
Array ('A' => 'gg ',' B '=> 'hh '));
Print_r ($ arr );
// Print_r output:
// Array ([0] => Array ([a] => aa [B] => bbb [c] => ccc)
[1] => Array ([a] => ddd [B] => eee [c] => fff)
[2] => Array ([a] => gg [B] => hh ))
Var_export ($ arr );
// Var_export output:
// Array (0 => array ('A' => 'A', 'B' => 'bbb ', 'c' => 'ccc ',),
1 => array ('A' => 'ddd ',' B '=> 'Eee', 'c' => 'fff ',),
2 => array ('A' => 'gg ',' B '=> 'hh ',),)
Var_dump ($ arr );
// Var_dump output:
/* Array (size = 3)
0 =>
Array (size = 3)
'A' => string 'aa' (length = 2)
'B' => string 'bbb '(length = 3)
'C' => string 'ccc '(length = 3)
1 =>
Array (size = 3)
'A' => string 'ddd '(length = 3)
'B' => string 'Eee '(length = 3)
'C' => string 'fff' (length = 3)
2 =>
Array (size = 2)
'A' => string 'gg '(length = 2)
'B' => string 'hh' (length = 2)
*/
The following output is in json format:
$ Arr = array ('A' => 'A', 'B' => 'bbb ', 'c' => 'ccc '),
Array ('A' => 'ddd ',' B '=> 'Eee', 'c' => 'fff '),
Array ('A' => 'gg ',' B '=> 'hh '));
$ Arra = json_encode ($ arr );
Print_r ($ arra );
// Print_r output:
[{"A": "aa", "B": "bbb", "c": "ccc" },{ "a": "ddd", "B ": "eee", "c": "fff" },{ "a": "gg", "B": "hh"}]
Var_export ($ arra );
// Var_export output:
'[{"A": "aa", "B": "bbb", "c": "ccc" },{ "a": "ddd ", "B": "eee", "c": "fff" },{ "a": "gg", "B": "hh"}]'
Var_dump ($ arra );
// Var_dump output:
String '[{"a": "aa", "B": "bbb", "c": "ccc" },{ "a": "ddd ", "B": "eee", "c": "fff" },{ "a": "gg", "B ": "hh"}] '(length = 84)
I think you can understand the specific differences.