PHP数组按位 [英] php array bitwise
本文介绍了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?
推荐答案
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.
这篇关于PHP数组按位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文