- var_dump: documentation ( source)
- bindec: documentation ( source)
- array_reverse: documentation ( source)
- decbin: documentation ( source)
- array_values: documentation ( source)
- str_pad: documentation ( source)
- str_split: documentation ( source)
<?php
$integer = 0b100101;
$binary = decbin($integer);
$binaries = str_split($binary, 1);
$binaries = array_reverse($binaries);
for ($index = 0; $index < count($binaries); $index++) {
$current = &$binaries[$index];
$current = str_pad("", ((count($binaries) - 1) - $index), "0") . $current . str_pad("", $index, "0");
$current = bindec($current);
if (empty($current)) {
//unset($binaries[$index]);
}
}
$binaries = array_values($binaries);
var_dump($binaries);