ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ <?php namespace app\index\controller; use app\index\model\Staff; class Index { public function destroyByClosure(){ //创建闭包函数 $closure = function ($query){ $query -> where(['name'=>['like','%阿%']]); }; //执行删除操作:条件由闭包函数提供 $affected = Staff::destroy($closure); //根据返回值判断是否删除成功 echo $affected ? '成功删除了'.$affected.'条记录!' : '删除失败~~'; } public function destroyById(){ //删除主键:1009,1010的记录 $affected = Staff::destroy([1009,1010]); //根据返回值判断是否删除成功 echo $affected ? '删除成功!' : '删除失败~~'; } public function destroyByCondition(){ //删除主键id在1019到1025之间的记录 $affected = Staff::destroy(['id'=>['between',[1019,1025]]]); //根据返回值判断是否删除成功 echo $affected ? '成功删除了'.$affected.'条记录!' : '删除失败~~'; } } ~~~