![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
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? |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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 |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#6 |
|
Programming Guru
![]() |
__________________
|
|
|
|
|
|
#7 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#8 | |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Quote:
|
|
|
|
|
|
|
#9 | |
|
Professional Programmer
|
Quote:
|
|
|
|
|
|
|
#10 |
|
Programming Guru
![]() |
He might be a patriotic terrorist with the use of colors in his post...
__________________
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|