PHP函数在使用变量时不返回替换的字符串

I am having trouble using a function for replacing text in my string, here is the function:

function decodeString($string){
$foo = "foo1";
$string = str_replace("foo",$foo,$string);
return $string;
}

I am accessing it from another page and the PHP file the function is in, is included before I try to use it.

decodeString($var1);

When it returns, the replacement is empty, so it just removed the word "foo", whereas if I don't use a variable in the replace function ($foo), and instead enter the text as a string there so "foo", then it returns with the text there, why can't it be returned if it's a variable?!! Don't understand this :(

The best and the recommended way to replace a string is to set a constant in the string, then using the str_replace function, for example:

$result = str_replace("[FIND]", "foo1", "This is my [FIND]");

Working example: function.onl/str_replace("[FIND]", "foo1", "This is my [FIND]");

Demo