PHP数组按​​位

问题描述:

如果我有标志的数组,我想他们按位一起结合

if I have an array of flags and I want to combine them with a bitwise conjunction

例如:

$foo = array(flag1, flag2);

$bar = flag1 | flag2;

PHP是否有什么好的功能,将做到这很好地为我了吗?

Does PHP have any good functions that will do this nicely for me already?

array_reduce 一>将降低一个数组单一值给你:

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.