Output array elements in PHP can be achieved through output statements, such as echo statements and print statements. However, in this output mode, only one element in the array can be output, and the array structure can be output through the print_r () function. Suppose there is an array:
What will the above code output? You can try the above results locally.
We usually use print_r to print the array (of course, var_dump can also be used, but the structure is not clear)
bool print_r ( mixed $expression [, bool $return ] )
Please print
print_r($names);
When the second parameter is true, print_r does not directly print the array, but returns the printed content as a string.
echo print_r($names, true);
We can use echo to print a string, integer, and floating point type, but we cannot use it to print an array.
An array is composed of a series of elements. to print an array, each element should be printed, rather than the entire array.
Output array elements in PHP can be achieved through output statements, such as echo statements and print statements. However, in this output mode, only one element in the array can be output, and the array structure can be output through the print_r () function.
The syntax format is as follows:
bool print_r(mixed expression)
If the expression parameter of the function is a common integer, string or real variable, the variable itself is output. If this parameter is an array, all elements in the array are output based on the key values and elements in sequence.
An instance of the print_r () function output array:
"PHP", 2 => "Chinese", 3 => "net"); print_r ($ array);?>
Output result:
[Recommended tutorials]
1. related topic recommendations: php Array (Array)
The above is the detailed description of the PHP output array-print the array instance. For more information, see other related articles in the first PHP community!