How can one effectively troubleshoot a PHP script that is not functioning as expected, such as a counter script?

Issue: If a PHP counter script is not functioning as expected, it could be due to incorrect variable initialization or manipulation within the script. To troubleshoot this issue, check the logic of the script to ensure that the counter variable is being properly incremented and displayed on the page.

<?php
// Initialize the counter variable
$counter = 0;

// Increment the counter variable
$counter++;

// Display the counter value
echo "Counter: " . $counter;
?>