php array bitwise
问题 if I have an array of flags and I want to combine them with a bitwise conjunction ie: $foo = array(flag1, flag2); into $bar = flag1 | flag2; Does PHP have any good functions that will do this nicely for me already? 回答1: The array_reduce will reduce an array to a single value for you: $res = array_reduce($array, function($a, $b) { return $a | $b; }, 0); Reduce is also sometimes called fold (fold left or fold right) in other languages. 回答2: You could do it like so $bar = $foo[0] | $foo[1] If