PHP print_r() Function Explained
In PHP, the print_r() function is used to print variables. It outputs the values of variables in a readable format, often used for debugging and inspecting the contents of variables.
The print_r() function takes a variable as a parameter and outputs the structure and values of that variable in a human-readable format to the output stream (usually a browser or terminal). It can handle various types of variables, such as arrays, objects, and strings.
Here is an example demonstrating how to use the print_r() function.
$array = array("apple", "banana", "cherry");
print_r($array);
In the example above, we created an array $array with three elements and printed its structure and values using the print_r() function. After running the code above, you will see something similar to the following in the output.
Array
(
[0] => apple
[1] => banana
[2] => cherry
)
This format makes it easier and more intuitive to view the contents of complex variables. Please note that the output of print_r() is typically used for development and debugging purposes and is not suitable for directly displaying information to end users.