Skip to content

Instantly share code, notes, and snippets.

@portapipe
Created October 1, 2019 09:31
Show Gist options
  • Save portapipe/b30de4ab3bc12ea87070276033518c03 to your computer and use it in GitHub Desktop.
Save portapipe/b30de4ab3bc12ea87070276033518c03 to your computer and use it in GitHub Desktop.
PHP Binary combinations of a given length
<?
$bits = 4; //Number of combinations
for($i=0;$i<=(pow(2,$bits)-1);$i++){
$bin = str_pad(decbin($i), $bits, '0', STR_PAD_LEFT);
echo '<pre>';var_dump($bin);echo '</pre>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment