how to get the cartesian index of variants

I have variants in a product page – every property has 2 variants for example

size : 40, 41

color : red, yellow

shape : circle, triangle

when I click on radio inputs I get the indices of the checked inputm for example [0,1,0]

So the question is how to make cartesian indices and then find the index using

$index = array_search($indices, $cartesian);

This is the screen shot of variants: