The variable is not completely passed through the global

Hello everyone! I ran into a joke, I have 3 files

  • config.php (contains settings)
  • index.php (main)
  • functions.php

config.phpcontains

$level['admin'] = "red";
$level['user'] = "orange";
$level['all'] = "black";

functions.php

function level($name, $id){
    global $level;
    if($id == 1)
        return "<font color=".$level['user'].">".$name."</font>";
    elseif($id == 2)
        return "<font color='".$level['admin']."'>".$name."</font>";
    else
        return "<font color='".$level['all']."'>".$name."</font>";
}

Index.php

print level($name, $id);

There are no errors. But the $level[] array only passes the first letter. If red, then “r”, if black, then “b”. Sample source code in browser

<font color="b">Node</font>

Answer 1, authority 100%

Check your $name before calling the function:

var_damp($name);

inside the function, after
global $level;

var_dump($level);

and everything hidden will become clear.

I bet that $name is garbage ..


Answer 2

Try replacing color names with 16 equivalents

red = #F00
orange = #FFA500
black = #000

Answer 3

It’s strange, but in one file everything works. Are you connecting all the files in index.php correctly?