Why am i getting 'unexpected t_global' in php?

Example:

function myFunction() {
    global $var;
    $var = 10;
}

This error may arise if you're trying to use the 'global' keyword outside of a function.

Solution:

Ensure you're using the 'global' keyword within a function to access a global variable.


$var = 5;

function myFunction() {
    global $var;
    $var = 10;
}

Beginner's Guide to PHP