Passed
Push — develop ( 4c5f84...237739 )
by Christophe
01:30
created

examples/BitArray.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * BitArray example
5
 *
6
 * @package BitArray
7
 *
8
 * @author    Christophe Demko <[email protected]>
9
 * @copyright Copyright (C) 2012-2023 Christophe Demko. All rights reserved.
10
 *
11
 * @license BSD 3-Clause License
12
 *
13
 * This file is part of the php-bitarray package https://github.com/chdemko/php-bitarray
14
 */
15
16
require __DIR__ . '/../vendor/autoload.php';
17
18
use chdemko\BitArray\BitArray;
19
20
// Print 10010
21
$bits = BitArray::fromString('10010');
22
echo $bits . PHP_EOL;
23
24
// Print 01101
25
$bits->applyComplement();
26
echo $bits . PHP_EOL;
27
28
// Print 11100
29
$bits->applyXor(BitArray::fromTraversable(array(true, false, false, false, true)));
0 ignored issues
show
array(true, false, false, false, true) of type array<integer,boolean> is incompatible with the type Traversable expected by parameter $traversable of chdemko\BitArray\BitArray::fromTraversable(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
$bits->applyXor(BitArray::fromTraversable(/** @scrutinizer ignore-type */ array(true, false, false, false, true)));
Loading history...
30
echo $bits . PHP_EOL;
31
32
// Print 11101
33
$bits[4] = true;
34
echo $bits . PHP_EOL;
35
36
// Print 0:1;1:1;2:1;3:;4:1;
37
foreach ($bits as $index => $value) {
38
    echo $index . ':' . $value . ';';
39
}
40
41
echo PHP_EOL;
42
43
// Print [true,true,true,false,true]
44
echo json_encode($bits) . PHP_EOL;
45