What is the purpose of using print_r in PHP and how does it work with arrays?
The purpose of using print_r in PHP is to display human-readable information about a variable, especially arrays. It helps developers debug and understand the structure and contents of an array easily. When used with arrays, print_r will display the keys and values of each element in the array.
// Sample array
$fruits = array("apple", "banana", "cherry");
// Display the contents of the array using print_r
print_r($fruits);
Keywords
Related Questions
- What are some potential issues to consider when subtracting time values in PHP, and how can they be addressed to ensure accurate results?
- How can PHP variables be extracted from an array after form submission?
- What are the best practices for formatting and retrieving date and time data from a MySQL database in PHP to avoid errors and inconsistencies?