Logical matrix operations for PHP