Jump to content

[SOLVED] "1.2.3.4.5" minus "2.4.5"


Evan69

Recommended Posts

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.