数组不清除因此插入重复的条目

时间:2015-12-17 17:46:43

标签: php mysql arrays

$data['subject'] = "Music > Cello";

$data['subject'] = "cello";



  $array = array();
  if (strpos($data['subject'], '>') != FALSE)
  {
  $array = explode(' > ', $data['subject']);
  $array[0]; // Music
  $array[1]; // Cello
  $subject = $array[1];
  $catname = $array[0];
  }
  else
  {
  $subject = $data['subject'];;
  }

//除非我刷新页面,否则会多次插入相同的数据。

 $sql="INSERT INTO search_history(place,budget,subject,level,datetime)VALUES('$location','$o_rate','$subject','$catname', now())";
            $stmt =connection::$pdo->prepare($sql);
            $stmt->execute();

为了防止我尝试的重复条目:

1)获取数组中的最后一项

   end($subject)<br/>
   end($catname)<br/>
   end($array)<br/>

2)

initialize array
  $array =array();

3)

unset($array);<br/>
   unset($subject);<br/>
  unset($catname);<br/>

0 个答案:

没有答案