CKTIS / PHP
AND bit a bit (&)
Estrae i flag comuni a due maschere.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
$value & $operandEstrae i flag comuni a due maschere. Il confronto del risultato con la maschera richiesta verifica la presenza di tutti i flag richiesti.
Una maschera agisce sui singoli bit degli interi. Quando entrambi gli operandi sono stringhe, PHP opera sui byte e restituisce una stringa. Un bit del risultato vale 1 quando entrambi i bit corrispondenti valgono 1.
Valutazione
12 & 10→812 & 0→07 & 7→7
Esempi
<?php
echo json_encode(12 & 10), PHP_EOL;
echo json_encode(12 & 0), PHP_EOL;
echo json_encode(7 & 7), PHP_EOL;
Risultato
8 0 7