为什么将字符串设置为变量与编写不带变量的字符串不同?

时间:2019-04-17 04:26:24

标签: php arrays string variables string-comparison

我有一个疑问,希望您能帮助我解决这个问题。

为什么当我将字符串设置为变量时,此脚本在PHP中不起作用?

<?php 

$arr = json_decode('[{"cat_id":"10399","cat_name":"Martin","parent_id":0},{"cat_id":"10","cat_name":"abc popi","parent_id":0},{"cat_id":"9","cat_name":"pedro","parent_id":0}]',true);

    $Namee = 'abc popi';

    array_filter($arr, function($people) {
        if ($people['cat_name'] == $Namee){
        echo '<br>Exists<br>';
        }
    });

?>

实际上,当我未将字符串设置为变量时,脚本可以完美运行:

<?php 

$arr = json_decode('[{"cat_id":"10399","cat_name":"Martin","parent_id":0},{"cat_id":"10","cat_name":"abc popi","parent_id":0},{"cat_id":"9","cat_name":"pedro","parent_id":0}]',true);


    array_filter($arr, function($people) {
        if ($people['cat_name'] == 'abc popi'){
        echo '<br>Exists<br>';
        }
    });

?>

0 个答案:

没有答案