Skip to content

Instantly share code, notes, and snippets.

@Arifursdev
Created April 7, 2024 15:43
Show Gist options
  • Save Arifursdev/47aeebd370e8c328bd2fa90e6084b3b8 to your computer and use it in GitHub Desktop.
Save Arifursdev/47aeebd370e8c328bd2fa90e6084b3b8 to your computer and use it in GitHub Desktop.
<?php
function progressBar($current, $total, $barLength = 50) {
$progress = ($current / $total) * 100;
$progressBar = floor(($progress / 100) * $barLength);
$emptyBar = $barLength - $progressBar;
ob_start();
echo "[";
for ($i = 0; $i < $progressBar; $i++) {
echo "=";
}
for ($i = 0; $i < $emptyBar; $i++) {
echo " ";
}
echo "] " . round($progress, 2) . "%\r";
echo ob_get_clean();
}
// Example Usage
$total = 100;
for ($i = 0; $i <= $total; $i++) {
progressBar($i, $total);
usleep(100000); // Simulate work (100ms)
}
echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment