方法代码:

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;
}
登录后复制
登录后复制

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


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

回复内容:

方法代码:

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;
}
登录后复制
登录后复制

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


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

array_filter($oldSegmentArray, function($s) use($vsuuid) {
    return $s !== $vsuuid;
});
登录后复制

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

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'");
}
登录后复制

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

08-24 05:36