Php 我的引用函数不起作用

Php 我的引用函数不起作用,php,Php,我有一个字符串,我用第二个arg true对它进行json_解码,得到一个assoc数组 我现在需要遍历其中的每个字符串并在其中删除斜线 所以我写了这个函数: function stripslashes_in_json(&$phpJsonDecodedTrue) { if (is_array($phpJsonDecodedTrue)) { foreach ($phpJsonDecodedTrue as &$v) { if (is_s

我有一个字符串,我用第二个arg true对它进行json_解码,得到一个assoc数组

我现在需要遍历其中的每个字符串并在其中删除斜线

所以我写了这个函数:

function stripslashes_in_json(&$phpJsonDecodedTrue) {
    if (is_array($phpJsonDecodedTrue)) {
        foreach ($phpJsonDecodedTrue as &$v) {
            if (is_string($v)) {
                $v = stripslashes($v);
            } else if (is_array($v)) {
                stripslashes_in_json($v);
            }
        }
    }
}

但是,它对我传递到这里的json解码的assoc数组没有影响,有人知道发生了什么吗?

您是否考虑过更简单的
数组\u walk\u递归($phpJsonDecodedTrue,function($v){$v=stripslashes($v);})
?这为您内部完成所有递归迭代。
array\u walk\u recursive
分开,您的代码对我来说很好。您的意思是什么?您指的是json中转义的某些字符(“,\,\n等)?这与
stripslashes
无关,只是正确构建json字符串的规则一些示例输入和预期输出会很有帮助。是的。否则您的json将无法正确解析