Jump to content

No repeating


rockinaway

Recommended Posts

I have some values e.g. 11112234444 and an array - $array

 

I want to do a check to see if they are present in $array, if they aren't then I want to add them in.

 

Then later I want to see if they are present in that $array (there should only be 1 occurrence of each value), and if they are, I want to echo out 'Yes' and REMOVE the occurrence from $array...

 

So for example:

 

1 is tested... it isn't in the array, so it is added in.. the others 1s are NOT added in, as there is already 1 in $array

 

Later I want to check for 1 in the $array again, and this time I want to remove it from the array, so that there isn't 1 left in the $array....

 

Any help on what I can do? Sorry hard to explain :S

Link to comment
Share on other sites

Lucky for you I just made the same sort of thing.

 

Study this:

$array = array("1","1","1","1","2","2","3","3","4","4");

for($i=0; $i <= count($array); $i++)
{
if( !in_array("{$array[$i]}", $array2) )
{
	$array2[] = $array[$i];
}
}

foreach( $array2 as $value )
{
echo $value; //should return 1234
}

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.