Can't access global variable inside function

In PHP, if you want to access a global variable inside a function, you need to use the "global" keyword. For example:

<?php

$x = "outside";

function test()
{
  global $x;
  echo $x;
}

test();

Watch a course Learn object oriented PHP

This will output "outside". Without the "global" keyword, the function would not be able to access the variable $x and would produce an error.