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
https://forums.phpfreaks.com/topic/91535-no-repeating/
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
https://forums.phpfreaks.com/topic/91535-no-repeating/#findComment-468876
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.