Skip to content

Instantly share code, notes, and snippets.

@megmorsie
Created April 21, 2016 17:40
Show Gist options
  • Save megmorsie/dcac67a17a7dbb893841987579eb2504 to your computer and use it in GitHub Desktop.
Save megmorsie/dcac67a17a7dbb893841987579eb2504 to your computer and use it in GitHub Desktop.
Increment Hex Values
<?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