By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,967 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,967 IT Pros & Developers. It's quick & easy.

remove odd data from array

P: 45
guys plz help,

i have an array(52,51,52)
here i want to insert first & last elements into DB, not second one does not follows the series

another array (52,52,53)
in this case insert first 2 elements into DB since last element does not follow the series.

how is this possible?
Apr 11 '12 #1
Share this Question
Share on Google+
3 Replies


P: 42
I'm not 100% sure what kind of patterns you may want to accept/deny, but you might try array_count_values: http://php.net/manual/en/function.ar...unt-values.php.
Apr 11 '12 #2

P: 93
Expand|Select|Wrap|Line Numbers
  1. $ary = array(12,13,14,12,12,14,16,15,17,12,16,13,14,13);
  2.  
  3. $ar_count = count($ary);
  4.  
  5. for($a=0;$a<$ar_count;$a++)
  6. {
  7.     if($ary[$a]%2 ==  0)
  8.      {
  9.           $vl = $ary[$a];
  10.          $qry = "insert into table_name values($vl)";
  11.           $query = mysql_query($qry) or die(mysql_error());
  12.      }
  13.  
  14. }
Try It............

Bharat Parmar(Bharat383)
Apr 14 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
I recommend array_filter().
Apr 16 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.