PHP string!= Variable ='string'[关闭]

Not sure how to name this question but I am looking for feedback to why when I set a variable to some string it will not let me call that variable in a function... For example:

$name = "name";
$quote_name = "'".$name."'";

//echo of $name = name
//echo of $quote_name = 'name'

PHP will not allow me to call:

if($value['name'] == $quote_name){...}

Or

if($value['name'] == '$name'){...}

But it WILL allow me to call (with the whole function):

foreach($question_set_p1 as $key => $value) {
    if($value['name'] == 'name') {
        $first = $key;
        break;
    }
}


$data =  array_filter($question_set_p1, function($arr){ 
    return $arr['name'] == 'name'; 
});

Why does PHP allow me to call the string but not the variable? Is there a way that I can state the variable and not the actual string?

Remove quote in second var, like this:

$name = "name";
$quote_name = $name;

if($value['name'] == $quote_name){...}

suppose

$value['name'] = 'abcd';
$name = 'abcd';
$quot_name = " ' ".$name." ' ";//(as you entered).

Now if you echo $quot_name it will return 'abcd' (with quotes) and if you echo $value['name'] it will return abcd (without quotes).

Therefore $quot_name should be $name (without quotes) or you should add quotes to $value['name'] too.