$colors = Array (' Red ', ' blue ', ' green ', ' yellow ');
Print_r ($colors);
Echo ' <br> ';
Var_dump ($colors);
The output results are as follows:
Array ([0] = red [1] = blue [2] = = Green [3] = = yellow)
Array (4) {[0]=> string (3) "Red" [1]=> string (4) "Blue" [2]=> string (5) "Green" [3]=> string (6) "Yellow"}
Var_dump can use any variable, including string, array, number, object, and also indicate the type and length of the variable. void
Var_dump(mixed expression [, mixed expression [, ...]])
This function displays structure information about one or more expressions, including the type and value of the expression. The array recursively expands the value and displays its structure by indentation.
Print_r () displays easy-to-understand information about a variable. If a string,integer , or floatis given, the variable value itself is printed. If an arrayis given, the keys and elements are displayed in a certain format. object is similar to an array.
Remember thatprint_r () moves the pointer of the array to the last edge.
Both the Print_r and var_dump can output arrays and objects, but the output of the Print_r to the boolean is not obvious; the var_dump output is verbose and much more commonly used for debugging.
The difference between Print_r and Var_dump