在php中替换全局变量

So as you can see here I have declared several variables that I use throughout my code. I cut the rest of it off but there's instances where you see I use global to reference to the variables stated above. My assignment requires us to not use the global variable and can't seem to scout the interwebs to find any potential solution to replacing global but still being able to use said variable(s). Any ideas?

//variables
$movie = $_GET["film"]; //dynamically get film name via link
$contents = file_get_contents("$movie/info.txt"); //get info of said film from /info file in my docs (name, rating, year)
$info = explode("
",$contents);
$sidecontents = file_get_contents("$movie/overview.txt"); //get all the credits (producer, ratings, etc) of film that is displayed below image
$b = explode("
",$sidecontents); //for every new line (in the txt they're in same line but theres the line break), split each string by string
$j = 0; //variable to use as a counter 

//rotten or fresh icon next to rating for movie
function percentLogo($inf)
{
    //if percentage of film is more than 60 then print fresh tomato
    if($inf >= 60)
    {
        ?> <img src='freshbig.png' alt='Fresh'/>
        <?php
    }
    //else, rotten tomato lol self explanatory but yeah
    else
    {
        ?> <img src='rottenbig.png' alt='Rotten'/>
<?php
    }
}
//info on the right sidebar of the page (not including the picture)
function sideinfo()
{
    global $b;
    foreach($b as $credits) //for each loop to increment through b (which is all the content we split for each line break) and store it in credits dynamically.
    { 
        $credits = explode(":",$credits); //we then split the string up for everytime we see a : and store it in credits again (bad programming practice but it's late so whatever lol)
        //essentially print out wh

While this an assignment, I will not do the work for you. However a push in the right direction usually does the trick. The idea of the test is how to use functions, properly.

function getMovieInfo(){
  $contents = file_get_contents($_GET["film"] . "/info.txt");
  # This variable is defined in a function, it is a local variable and not global.

  return explode("
",$contents);
}

print_r(getMovieInfo());

Instead of storing a value in a variable, you return it. In this case you return an array but you can process information in the function to return something specific.

Using function arguments you can make it a little more dynamic:

function getMovieInfo($file){
  return explode("
",file_get_contents("$file/info.txt"));
  # -------------------------------------^ nameofmovie/info.txt
}

print_r(getMovieInfo("nameofmovie"));