单选题
入库
$file = fopen("./shiti.txt", "r"); $contentArr=array(); $i=0; //输出文本中所有的行,直到文件结束为止。 while(! feof($file)) { $contentArr[$i]= fgets($file);//fgets()函数从文件指针中读取一行 $i++; } fclose($file); //$contentArr = array_filter($contentArr); $Shiti = new ShitiModel(); $k = 0; $arr = []; $list = ['title','a','b','c','d','answer','空','']; $bArr = []; foreach($contentArr as $key=>$val){ if($k>=7){ $k = 0; //print_r($arr); $info = $Shiti->where('title',$arr['title'])->value('title'); if(empty($info)){ $bArr[] = $arr; $Shiti->insert($arr); } //$bArr[] = $arr; } if($kinsertAll($bArr); exit;
出库
$Shiti = new ShitiModel(); $list = $Shiti->select(); foreach($list as $key=>$val){ echo $key+1 . '.' .$val['title']; echo '
'; echo $val['a'].'
'; echo $val['b'].'
'; echo $val['c'].'
'; echo $val['d'].'
'; echo $val['answer'].'
'; echo '
'; } print_r($list); exit;
多选题
入库
$file = fopen("./shiti.txt", "r"); $contentArr=array(); $i=0; //输出文本中所有的行,直到文件结束为止。 while(! feof($file)) { $contentArr[$i]= fgets($file);//fgets()函数从文件指针中读取一行 $i++; } fclose($file); //$contentArr = array_filter($contentArr); $Shiti = new ShitiModel(); $k = 0; $arr = []; $list = ['title','a','b','c','d','e','answer','空','']; $bArr = []; foreach($contentArr as $key=>$val){ if($k>=8){ $k = 0; //print_r($arr); $info = $Shiti->where('title',$arr['title'])->value('title'); if(empty($info)){ $bArr[] = $arr; $Shiti->insert($arr); } //$bArr[] = $arr; } if($kinsertAll($bArr); exit;
出库
$Shiti = new ShitiModel(); $list = $Shiti->select(); foreach($list as $key=>$val){ echo $key+1 . '.' .$val['title']; echo '
'; echo $val['a'].'
'; echo $val['b'].'
'; echo $val['c'].'
'; echo $val['d'].'
'; echo $val['e'].'
'; echo $val['answer'].'
'; echo '
'; } print_r($list); exit;