Oihana PHP

hasFlag.php

Table of Contents

Functions

hasFlag()  : bool
Checks whether a specific flag is set in a bitmask.

Functions

hasFlag()

Checks whether a specific flag is set in a bitmask.

hasFlag(int $mask, int $flag) : bool

This function is useful when working with bitwise flags. You can combine multiple flags using the bitwise OR operator (|) and then check if a particular flag is present in the combined mask.

Parameters
$mask : int

The bitmask value, potentially containing multiple flags combined with |.

$flag : int

The specific flag to check for in the mask.

Tags
example
use function oihana\core\bits\hasFlag;

const FLAG_A = 1 << 0;
const FLAG_B = 1 << 1;

$mask = FLAG_A | FLAG_B;

hasFlag($mask, FLAG_A); // true
hasFlag($mask, FLAG_B); // true
hasFlag($mask, 1 << 2); // false
author

Marc Alcaraz (ekameleon)

since
1.0.7
Return values
bool

Returns true if the given flag is present in the mask, false otherwise.


        
On this page

Search results