为什么这个PHP代码输出正确?

Yo, I'm studying and relearning some old PHP basics and I got to superglobals

I don't quite understand why this PHP code is as well as why the superglobal doesn't add to be 15 when logically 10 isn't 15, and help or pointers so I can understand this?

$y = 10;
$x = 5;

$GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];

I've tried researching this on my own and accepting its because y is just the name of the super global index

none to show other than what's in the question

<?php 
$x = 5; 
$y = 10; 

function myTest() { 
    $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y']; 
} 
myTest(); 
echo $y; // outputs 15 
?>

the only error here is my brain

When I look at the code I see $GLOBAL['10'] = $GLOBAL['5'] + $GLOBALS['10'];

I don't understand how 15 can equal 10.

When you refer to a variable outside a function it refers to the global variable. When you refer to a variable inside a function, it normally refers to the local variable, unless the function contains a global declaration that makes that variable global.

You can also use the super-global $GLOBALS, which always refers to the global variables named in its keys. The documentation describes it as:

An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.

So when you use $GLOBALS['y'] it's the same as using the global variable $y. Your function is equivalen to:

function myTest() { 
    global $x, $y;
    $y = $x + $y;
}