Q:

How Do I Get This PHP Working?

I was hoping the below would print 
live
got here

Instead it prints
got here

The code:
$config['env'] = 'live';

sayEnvironment();

function sayEnvironment () {

  echo $config['env'];
  echo 'got here';

}

How do I set this global variable and have everything inside a function access it?

A:

Use global to use global variables inside functions:
$config['env'] = 'live';

sayEnvironment();

function sayEnvironment () {
  global $config;
  echo $config['env'];
  echo 'got here';
}

Or if you have anonymous function, you can use use:
$sayEnvironment2 = function () use ($config) {
    echo $config['env'];
    echo 'got here';
};

$sayEnvironment2(); // must be called AFTER php parser has seen actual function.

Sample

