Created
April 7, 2024 15:43
-
-
Save Arifursdev/47aeebd370e8c328bd2fa90e6084b3b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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