In PHP, to output an array variable, you can use the following method:
print_r() is a method in PHP Variables A function that formats output in an easy-to-understand form. It can be used to output various types of variables such as strings, numbers, and arrays. When used with an array, print_r() will output the contents of the array as key-value pairs. Here is an example:
$array = array("foo", "bar", "baz"); print_r($array);
The output is as follows:
Array ( [0] => foo [1] => bar [2] => baz )
In addition to using print_r() In addition to functions, you can also use the echo() function to directly output the string representation of an array. This can be achieved by casting the array variable to a string, for example:
$array = array("foo", "bar", "baz"); echo implode(", ", $array);
The output will be as follows:
foo, bar, baz
$array = array("foo", "bar", "baz"); var_dump($array);
array(3) { [0]=> string(3) "foo" [1]=> string(3) "bar" [2]=> string(3) "baz" }
The above is the detailed content of How to output array variables in php. For more information, please follow other related articles on the PHP Chinese website!