After "and" how to store queries

background

An article about the "storage and computing-many relationship" , you can check out the ape mastered a programming language through the operation of the database. How to query an ape grasp what kinds of language?

method one

1. the value of the programming language query ape A storage (194)

2. Query all programming languages and language names 2 ^ values corresponding to an array
($ languages = [[1 = > 'Java'), [2 => 'C'], [3 => 'C ++'] ... .])

3. By circulation, and screening operation ape A master programming language

    foreach($languages as $languageId => $languageName ){
        if($languageId & 194 == $languageId){
            //掌握的语言
            //C语言(2) 、 PHP(64) 、 JavaScript(128)
        }
    }

Method Two

The above method will check out all programming languages, can not be launched by the anti-194 is the result of which several programming languages ​​"and" out of it?

$bin =  decbin(194);//11000010 
function getArray($bin){
    $data = [];
    $len = mb_strlen($bin,'utf-8');//8
    $index = $len - 1;
    for($i=0;$i<=$index;$i++){
        $num = $bin[$i];
        if($num <> 0){
            $data[] = pow(2,$index-$i);
        }
    }
    return $data;
}
getArray($bin);//[128,64,2]

Guess you like

Origin www.cnblogs.com/luyuqiang/p/how-to-handle-and-operator.html