From your question my understanding is that you are confused how the different iteration of the getDeepKeys()
method knows to which keys
variable it should save the value.
then after calling the function, an empty key array is created again keys
Yes it creates another variable named keys. But unlike we human computer identify each keys by their address in the memory. You can declare as many variable with same name as you want in different iteration of the method. They will be stored in different memory location in your PC. That is why the getDeepKeys()
method never confuses to which keys
it should save the array.
Lets say for the first iteration when you create the keys array it is being stored in the memory location 10AD32
and for the 2nd iteration when you create another keys array it will be stored in a different memory location such as 11CD34
. Therefore although both variable have name keys
but computer can identify them differently.
So for each iteration you will have a different keys variable.
For better understanding you can read this, this and this.
Note that when describing the array storing procedure I intentionally over simplified it for you. The whole array will not stored in a single memory location. In reality the array name refers to the position where the array head is stored.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…