Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 18th, 2005, 11:35 PM   #1
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 172
Rep Power: 3 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
Exclamation Comparing an array

Alright, I've been working on this problem for a while. I have the array invloving these items:

tnt, school, staff, pictures, other, new, school, pictures, new, other, crap, junk, etc.

I have been trying to write a php script that will eliminate all the ones that occur the 2nd time so I would want the array above to look like this:

tnt, school, staff, pictures, other, new, crap, junk, etc.

See how they only are represented once...That's what i need, anyone got any ideas?
PhilBon is offline   Reply With Quote
Old Nov 19th, 2005, 6:52 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I suggest you check out the modulus operator (in PHP, this is the % character). It gives you the remainder of a number when divided by another. For example,
5 % 3 == 2
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 19th, 2005, 7:21 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I think you need to be more specific regarding the construction of the array(s) in question. Textual or numeric keys? Duplicates of 2nd dimension array? I'm at a loss as to application of the modulus operator, but one never knows -- perhaps you have a really strange setup. I'm pretty sure the red and blue have nothing to do with it.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 19th, 2005, 7:32 AM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
From what I can tell, he has an array, and he wants to remove every second item. I would personally iterate through, check whether the element number is evenly divisible by two, and remove based on the result.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 19th, 2005, 7:53 AM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I didn't pick up on it that way, "school" being in the second and seventh elements in the example.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 19th, 2005, 8:07 AM   #6
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
http://php.net/array_unique
__________________

tempest is offline   Reply With Quote
Old Nov 19th, 2005, 8:58 AM   #7
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by PhilBon
[color=Blue]tnt, school, staff, pictures, other, new, school, pictures, new, other, crap, junk, etc.
If these are your priorities in life, I think you would be a terrorist, with having TNT first. If array_unique is not what you need then just loop through the array and look at the items you have already had and do something with them.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Nov 19th, 2005, 10:44 AM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Quote:
Originally Posted by DaWei
I didn't pick up on it that way, "school" being in the second and seventh elements in the example.
Damnit! Stop misreading questions, Oobs!
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 19th, 2005, 11:48 AM   #9
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
Quote:
Originally Posted by nnxion
If these are your priorities in life, I think you would be a terrorist, with having TNT first. If array_unique is not what you need then just loop through the array and look at the items you have already had and do something with them.
lol, wow.
__________________
--John Cruz
Web Developer
www.cruzweb.net
Lich is offline   Reply With Quote
Old Nov 19th, 2005, 3:14 PM   #10
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
He might be a patriotic terrorist with the use of colors in his post...
__________________

tempest is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC