Created
April 21, 2016 17:40
-
-
Save megmorsie/dcac67a17a7dbb893841987579eb2504 to your computer and use it in GitHub Desktop.
Increment Hex Values
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 | |
// This file increments hex values and keeps any leading zeroes. | |
// Example: Use to generate a list of MySQL CREATE DATABASE functions to set up database shards. | |
$x = 0; // Counter | |
$hex = "00"; // When the amount of digits changes in $hex, remember to change the str_pad() function, too. | |
while ($x < 256) { // The amount of times to loop. | |
echo "$hex <br />"; | |
$hex = dechex(hexdec($hex)+1); // Increment the hex value. | |
$hex = str_pad($hex, 2, "0", STR_PAD_LEFT); // Keep leading zeroes up to 2 digits. | |
$x ++; // Counter | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment