To print an array in PHP, you can use the print_r
function. This function prints the contents of an array in a human-readable format.
Here is an example of how to use print_r
to print an array:
$array = array(1, 2, 3, 4, 5); print_r($array);
This will output the following:
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
You can also use the var_dump
function to print an array. This function prints more detailed information about the array, including its data type and size.
Here is an example of how to use var_dump
to print an array:
$array = array(1, 2, 3, 4, 5); var_dump($array);
This will output the following:
array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) }
It's important to note that print_r
and var_dump
are just two of the many functions and techniques that you can use to print an array in PHP. Consult the PHP documentation for more information.