Oihana PHP

toggleFlag.php

Table of Contents

Functions

toggleFlag()  : int
Toggles a specific flag in a bitmask.

Functions

toggleFlag()

Toggles a specific flag in a bitmask.

toggleFlag(int $mask, int $flag) : int

If the flag is present, it will be removed; if absent, it will be added.

Parameters
$mask : int

The original bitmask.

$flag : int

The flag to toggle.

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

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

$mask = FLAG_A;        // 1
$mask = toggleFlag($mask, FLAG_B);
// $mask is now 3 (FLAG_A | FLAG_B)

$mask = toggleFlag($mask, FLAG_A);
// $mask is now 2 (FLAG_B only)
author

Marc Alcaraz (ekameleon)

since
1.0.7
Return values
int

The new bitmask with the flag toggled.


        
On this page

Search results