Hihi..
Am creating a permissions sytem which uses bitwise/binary to store permissions..
The 'problem' I am facing atm, is that the client can create their own permissions.. thus when I display the permissions, I need to be able to look at the length of the binary string, and loop through each one to see whether it is 'set' or not..
outputting:
how can I loop through a binary string, whilst knowing what integer value $i will be?
can't substr or explode as that will shift the numbers (explode equating to every number being (int) 1 or (int) 0)
My maths is sucky sucky, so don't know of any equation or anything to do this.
TIA
EDIT:
And like the typical 'mate, can you help me out with this? I can't get it to.. oh, nvm.. fixed' situation.. I solved the 'problem' before clicking submit.. and realised it was a hell of a lot simpler than I thought.. so am posting for you all to call me a noob
Am creating a permissions sytem which uses bitwise/binary to store permissions..
The 'problem' I am facing atm, is that the client can create their own permissions.. thus when I display the permissions, I need to be able to look at the length of the binary string, and loop through each one to see whether it is 'set' or not..
Code:
$perms = '111011';
for ($i = 1; [$i is in $perms]; $i = <this is the bit I can't work out..>) {
echo (($perms & $i) > 0) ? 'set' : 'not set') . "\n";
}
outputting:
Code:
set
set
not set
set
set
can't substr or explode as that will shift the numbers (explode equating to every number being (int) 1 or (int) 0)
My maths is sucky sucky, so don't know of any equation or anything to do this.
TIA

EDIT:
And like the typical 'mate, can you help me out with this? I can't get it to.. oh, nvm.. fixed' situation.. I solved the 'problem' before clicking submit.. and realised it was a hell of a lot simpler than I thought.. so am posting for you all to call me a noob

Code:
while ($row = $db->getRow()) {
$perms = decbin($row['permissions']);
for ($i = 1, $j = 0; $j < strlen($perms); $i = $i * 2, $j++) {
echo (($perms & $i) > 0 ? 'set' : 'not set') . "<br />\n";
}
}