M999
M999

Reputation: 25

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?

Upvotes: 1

Views: 49

Answers (2)

Manh Nguyen
Manh Nguyen

Reputation: 940

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

Upvotes: 1

Eduardo
Eduardo

Reputation: 2279

What about storing instances of an object where the object contains two index properties and a value property

Upvotes: 0

Related Questions