Jump to content
  • 0

H> To Remove duplicates from Array


Question

Posted (edited)

Eg:  if an array set has this :

 setarray .@item_id, 501,502,503,504,505,509,506,507,508,509,510,501;

how to turn it to become like this :

 setarray .@item_id, 501,502,503,504,505,506,507,508,509,510;

Note: original Array is actually iteminventorylist so it is not in any sorting orders.

Edited by utofaery

1 answer to this question

Recommended Posts

  • 0
Posted

Like this?

	for(.@size = getarraysize(.@array);.@i < .@size;.@i++) {
		.@count = countinarray(.@array[.@i],.@array[0]);
		if(.@count > 1) {
			.@val = .@array[.@i];
			.@k = .@count - 1;
			do {
				.@j = inarray(.@array,.@val);
				if(.@j >= 0)
					deletearray .@array[.@j],1;
			} while(.@j != -1 && .@k--);
			.@size-= (.@count - 1);
			.@i-= (.@count - 1);
		}
	}

 

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...