Read key in array – PHP

My array is:

[SCHOOL] => Array
  (
    [0] => Array(
      [SCHCODE] => 0001[QTY1] => 1
    )

    [17] => Array(
      [SCHCODE] => 0002[QTY1] => 10
    )

  )

The second array with key=17 is created automatically (it does not matter much) and the key gets a random value like 17 from a counter.
How can I read the previous key which in our case is 0 and increase it each time by one. So instead of 17 to write 1