Evan69 Posted December 26, 2007 Share Posted December 26, 2007 Hi, im working on a script where i have the user ids stored in a field separated by periods. I am trying to create a function that can subtract two sets of users so it would basically complete the equation: 1.2.3.4 - 2.4 = 1.3 So far i have managed to get it so you can subract one number from an array, but i am stuck as to how i would subract a set of numbers? Heres the code i have, theres so other stuff in there that isnt so important, its the second half of the function that matters: function get_users($minus) { $this->query = mysql_query("SELECT * FROM cal_users"); $num = mysql_num_rows($this->query); $users = array(); $out = array(); if($num > 0) { while($res = mysql_fetch_assoc($this->query)) { array_push($users, $res); } }else{ $users = ''; } //This is whats important if($minus > 0) { $del = explode(".", $minus); foreach($users as $user) { if($user['id'] == $minus) { continue; }else{ array_push($out, $user); } } }else{ $out = $users; } return $out; } Any help would be much appreciated! Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 26, 2007 Share Posted December 26, 2007 try this <?php $strData = "1.2.3.4"; $strMinus = "2.4"; $arrData = explode(".",$strData); $arrMinus = explode(".",$strMinus); $arrResult = array_diff($arrData,$arrMinus); print_r($arrResult); ?> you can incorperate the same in your code.. hope its helpful Quote Link to comment Share on other sites More sharing options...
Evan69 Posted December 26, 2007 Author Share Posted December 26, 2007 thanks alot, it works perfect. i knew my way was way too complicated! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.