What are some debugging techniques, like using print_r(), to understand query results in PHP?

One common debugging technique in PHP is using print_r() to display the contents of a variable or array. This can be helpful in understanding query results and identifying any issues with the data being returned from a database query. By using print_r(), you can easily see the structure and values of the query results, which can aid in troubleshooting and resolving any issues.

$query = "SELECT * FROM users";
$result = mysqli_query($connection, $query);

if($result){
    while($row = mysqli_fetch_assoc($result)){
        print_r($row);
    }
} else {
    echo "Error: " . mysqli_error($connection);
}