首页  >  文章  >  后端开发  >  php变量访问权限问题?

php变量访问权限问题?

WBOY
WBOY原创
2016-06-06 20:35:121439浏览

方法代码:

<code>function deleteSegment($vsuuid) {
    $num = db("test")->exec("DELETE FROM t_segment_index WHERE vs_uuid='$vsuuid'");
    if($num == 1) {
        $del = db("test")->exec("DELETE FROM t_video_segment WHERE vs_uuid='$vsuuid'");
        if($del == 1){
            $vsu = $vsuuid;
            $videoMsg = db("test")->getQuery("SELECT * FROM `t_video` where v_segments_list like '%$vsuuid%' limit 1");
            if(empty($videoMsg))
                return $del;
            $segments = $videoMsg[0]["v_segments_list"];
            $v_uuid = $videoMsg[0]["v_uuid"];
            $oldSegmentArray = explode("\n", $segments);
            $newSegmentArray = array_filter($oldSegmentArray, function($s){
                if($s === $vsuuid)
                    return false;
                else
                    return true;
            });
            $newSegments = implode("\n", array_values($newSegmentArray));
            $updateV = db("test")->exec("UPDATE t_video SET v_segments_list = '$newSegments' WHERE v_uuid='$v_uuid'");
            return 1;
        } else
            return 0;
    } else
        return 0;
}
</code>

代码执行到if($s === $vsuuid)的时候报错如下:
Notice: Undefined variable: vsuuid in /Applications/XAMPP/xamppfiles/htdocs/waaa-web/runtime/service_Admin.php on line 1526


请问是什么原因导致的?该怎么解决呢?

回复内容:

方法代码:

<code>function deleteSegment($vsuuid) {
    $num = db("test")->exec("DELETE FROM t_segment_index WHERE vs_uuid='$vsuuid'");
    if($num == 1) {
        $del = db("test")->exec("DELETE FROM t_video_segment WHERE vs_uuid='$vsuuid'");
        if($del == 1){
            $vsu = $vsuuid;
            $videoMsg = db("test")->getQuery("SELECT * FROM `t_video` where v_segments_list like '%$vsuuid%' limit 1");
            if(empty($videoMsg))
                return $del;
            $segments = $videoMsg[0]["v_segments_list"];
            $v_uuid = $videoMsg[0]["v_uuid"];
            $oldSegmentArray = explode("\n", $segments);
            $newSegmentArray = array_filter($oldSegmentArray, function($s){
                if($s === $vsuuid)
                    return false;
                else
                    return true;
            });
            $newSegments = implode("\n", array_values($newSegmentArray));
            $updateV = db("test")->exec("UPDATE t_video SET v_segments_list = '$newSegments' WHERE v_uuid='$v_uuid'");
            return 1;
        } else
            return 0;
    } else
        return 0;
}
</code>

代码执行到if($s === $vsuuid)的时候报错如下:
Notice: Undefined variable: vsuuid in /Applications/XAMPP/xamppfiles/htdocs/waaa-web/runtime/service_Admin.php on line 1526


请问是什么原因导致的?该怎么解决呢?

<code>array_filter($oldSegmentArray, function($s) use($vsuuid) {
    return $s !== $vsuuid;
});
</code>

顺便帮你改下下函数...

<code>function deleteSegment($vsuuid) {
    $res = db("test")->exec("DELETE FROM t_segment_index, t_video_segment WHERE vs_uuid='$vsuuid'");
    if( !$res ) return 0;

    $videoMsg = db("test")->getQuery("SELECT * FROM `t_video` where v_segments_list like '%$vsuuid%' limit 1");
    if( empty($videoMsg) ) return 0;

    $segments = $videoMsg[0]["v_segments_list"];
    $v_uuid = $videoMsg[0]["v_uuid"];
    $oldSegmentArray = explode("\n", $segments);
    $newSegmentArray = array_filter($oldSegmentArray, function($s) use($vsuuid) { return $s !== $vsuuid; });
    $newSegments = implode("\n", array_values($newSegmentArray));

    return $updateV = db("test")->exec("UPDATE t_video SET v_segments_list = '$newSegments' WHERE v_uuid='$v_uuid'");
}
</code>

闭包(Closure) 中使用外部函数,function($param) use($otherParam){}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn