计算自索引和数组以来哪个位置是我的图片

$quarter is a array who contain the list of all quarter in my database and each quarter have a total number of picture in each quarter (A, B, C)

$quarter = ['A' => '2', 'B' => '5', 'C' => '3'];

Quarter A has 2 pictures (0001 and 0002) Quarter B has 5 pictures (0001 to 0005) Quarter C has 3 pictures (0001 to 0003)

The index is the total position of the picture without worry about the quarter

$index = 3;

And I would like to return me

['quarter' => 'B', 'index' => 1]

Because the third picture is in quarter B, The quarter A has two first picture and the quarter B begin to third pictures. I would like to create algo who return the position of my picture (quarter with index of its quarter) since the number of pictures

Example 2

$index = 7;
$begin = 'B'

It return me

['quarter' => 'C', 'index' => 2]

Because it begin the calcul in quarter B. Of course this example has alpha quarter but In fact my quarters is a number.

Thanks

$quarter = ['A' => '2', 'B' => '5', 'C' => '3'];
$index = 7;
$begin = 'B';

// If $index more than amount of pics upto array end, result is empty array
$res = [];

// Remove items before `B` key
$temp = array_slice($quarter, array_search($begin, array_keys($quarter)));
foreach($temp as $k => $pics) {
   if ($index <= $pics) { $res = [$k => $index]; break; }
   else $index -= $pics;
 }  
print_r($res) ;