php变量访问权限问题?

WBOY
Release: 2016-06-06 20:35:12
Original
1441 people have browsed it

方法代码:

<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>
Copy after login
Copy after login

代码执行到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>
Copy after login
Copy after login

代码执行到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>
Copy after login

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

<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>
Copy after login

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

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template