单选题
入库
$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($k<6){ $arr[$list[$k]] = trim($val); } $k ++; } //$Shiti->insertAll($bArr); exit;
出库
$Shiti = new ShitiModel(); $list = $Shiti->select(); foreach($list as $key=>$val){ echo $key+1 . '.' .$val['title']; echo '<br>'; echo $val['a'].'<br>'; echo $val['b'].'<br>'; echo $val['c'].'<br>'; echo $val['d'].'<br>'; echo $val['answer'].'<br>'; echo '<br>'; } 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($k<7){ $arr[$list[$k]] = trim($val); } $k ++; } //$Shiti->insertAll($bArr); exit;
出库
$Shiti = new ShitiModel(); $list = $Shiti->select(); foreach($list as $key=>$val){ echo $key+1 . '.' .$val['title']; echo '<br>'; echo $val['a'].'<br>'; echo $val['b'].'<br>'; echo $val['c'].'<br>'; echo $val['d'].'<br>'; echo $val['e'].'<br>'; echo $val['answer'].'<br>'; echo '<br>'; } print_r($list); exit;