remove odd data from array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • charles07
    New Member
    • Dec 2011
    • 45

    remove odd data from array

    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?
  • Marknut
    New Member
    • Apr 2010
    • 42

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

    Comment

    • Bharat383
      New Member
      • Aug 2011
      • 93

      #3
      Code:
      $ary = array(12,13,14,12,12,14,16,15,17,12,16,13,14,13);
      
      $ar_count = count($ary);
      
      for($a=0;$a<$ar_count;$a++)
      {
          if($ary[$a]%2 ==  0)
           {
                $vl = $ary[$a];
               $qry = "insert into table_name values($vl)";
                $query = mysql_query($qry) or die(mysql_error());
           }
      
      }
      Try It............

      Bharat Parmar(Bharat38 3)
      Last edited by Dormilich; Apr 16 '12, 12:49 PM. Reason: Please use [CODE] [/CODE] tags when posting code.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I recommend array_filter().

        Comment

        Working...