How to share variables within multiple PHP tags on a page?

I want to share variables in different tags in the following way, but I can"t do it, and I"ve tried $_ SESSION,.

<form method="get">
    <input type="text" name="num1" placeholder="num1">
    <input type="text" name="num2" placeholder="num2">
    <button type="submit" name="submit" value="func1"></button>
</form>

The result is: <?php
if (isset($GLOBALS["result"])) {
    echo "111";
    echo $GLOBALS["result"];
}
?>


<?php

$GLOBALS["result"] = 0;


if(isset($_GET["submit"]) && $_GET["submit"] == "func1"){
    $num1 = $_GET["num1"];
    $num2 = $_GET["num2"];

    $GLOBALS["result"] = $num1 + $num2;

}

?>

Php
Apr.09,2021

the PHP script executes from top to bottom

$GLOBALS ['result'] is not defined at first, and then the first you must not be able to output

of your following results.

you can pass the result through GET or POST . $_ SESSION is definitely available, but you have to session_start ();

first.
The

code is parsed from top to bottom. When you refer to it, the variables are not defined, and of course you can't get the result

.

define first and then take the value . All languages are the same. Adjust the positions of the upper and lower php tags

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e47bb5-44c51.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e47bb5-44c51.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?