M999 M999 - 1 month ago 10
PHP Question

How to store indices of an array in an interger?

I have an array as follows:

$categories = [
0 => 'a',
1 => 'b',
2 => 'c',
3 => 'd',
4 => 'e',
5 => 'f',
];


Is there a way to use an integer variable that can store multiple indexes of $categories?

Eg:

$x = a (an integer number). It means $x contains 0, 1
$x = b (an integer number). It means $x contains 1, 2
etc,


Could anyone tell me how to do it?

Answer

Try Bitwise operators. Bitwise operators allow evaluation and manipulation of specific bits within an integer.