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


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


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>";
        return "<font color='".$level['all']."'>".$name."</font>";


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:


inside the function, after
global $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?