方法代码:
<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){}

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
