For the purposes of passing along the attributes as a json array, I wanted to pass the attributes as an indexed array to save on bandwidth and session storage. The human readable translation is then performed in javascript by relating each key to the proper attribute label. I also wanted a cleaner way of converting the attributes without calling another function or using a complex iteration. This puts each binary attribute into it's own array element for easy testing.
<?php
$mailboxes = imap_getmailboxes($mailbox, $username, $password);
foreach($mailboxes as $key=>$mailbox){
...
$attrs = preg_split('//',str_pad(decbin($mailbox->attributes),7,"0",STR_PAD_LEFT),8); array_shift($attrs); ...
}
?>
With temporary variables, the conversion would look like this.
<?php
$attr_binary = decbin($mailbox->attributes); $attr_binary = str_pad($attr_binary,7,"0",STR_PAD_LEFT); $attrs = $preg_split('//',$attr_binary,8); array_shift($attrs); ?>
By defining the attributes as a map to the array index, you can test as follows.
<?php
define("ATTR_NOINFERIORS",6);
define("ATTR_NOSELECT "5);
define("ATTR_MARKED ",4);
define("ATTR_UNMARKED ",3);
define("ATTR_REFERRAL ",2);
define("ATTR_HASCHILDREN ",1);
define("ATTR_HASNOCHILDREN ",0);
if ($attrs[ATTR_HASCHILDREN]){
}
?>