Jump to content

array_unique


jaay

Recommended Posts

I have certain fields in DB table that are actually comma separated words like mango,orange,apple. Now I make an array with rows from the table like

 

mango,orange,apple and peach,cherry,apple etc. Now if I make an array with this and explode to find comma delimited value it looks like,

 

mango orange apple peach cherry apple.

 

Now as you can see apple appears twice. I want it to appear only once. I used array_unique but that doesnt seem to work. How to do this. Please help?

Link to comment
Share on other sites

here is the echo from the var_dump .....

 

array(4) { [0]=>  string(4) "beer" [1]=>  string(8) " alcohol" [2]=>  string(6) " apple" [3]=>  string(7) " cherry" } array(4) { [0]=>  string(4) "beer" [1]=>  string(8) " alcohol" [2]=>  string(6) " apple" [3]=>  string(7) " cherry" } array(4) { [0]=>  string(4) "beer" [1]=>  string(8) " alcohol" [2]=>  string(6) " apple" [3]=>  string(7) " cherry" } array(4) { [0]=>  string(4) "beer" [1]=>  string(8) " alcohol" [2]=>  string(6) " apple" [3]=>  string(7) " cherry" } array(4) { [0]=>  string(5) "ac-dc" [1]=>  string(5) " rock" [2]=>  string(6) " music" [3]=>  string(4) "band" } array(4) { [0]=>  string(5) "ac-dc" [1]=>  string(5) " rock" [2]=>  string(6) " music" [3]=>  string(4) "band" } array(4) { [0]=>  string(5) "ac-dc" [1]=>  string(5) " rock" [2]=>  string(6) " music" [3]=>  string(4) "band" } array(4) { [0]=>  string(5) "ac-dc" [1]=>  string(5) " rock" [2]=>  string(6) " music" [3]=>  string(4) "band" } array(4) { [0]=>  string(4) "rock" [1]=>  string(6) " music" [2]=>  string(2) "30" [3]=>  string(11) " television" } array(4) { [0]=>  string(4) "rock" [1]=>  string(6) " music" [2]=>  string(2) "30" [3]=>  string(11) " television" } array(4) { [0]=>  string(4) "rock" [1]=>  string(6) " music" [2]=>  string(2) "30" [3]=>  string(11) " television" } array(4) { [0]=>  string(4) "rock" [1]=>  string(6) " music" [2]=>  string(2) "30" [3]=>  string(11) " television" } array(3) { [0]=>  string(5) "apple" [1]=>  string(5) " beer" [2]=>  string(6) " mango" } array(3) { [0]=>  string(5) "apple" [1]=>  string(5) " beer" [2]=>  string(6) " mango" } array(3) { [0]=>  string(5) "apple" [1]=>  string(5) " beer" [2]=>  string(6) " mango" } array(7) { [0]=>  string(4) "beer" [1]=>  string(6) " belly" [2]=>  string(8) " alcohol" [3]=>  string(6) " drunk" [4]=>  string(6) " funny" [5]=>  string(4) " sex" [6]=>  string(8) " machine" } array(7) { [0]=>  string(4) "beer" [1]=>  string(6) " belly" [2]=>  string(8) " alcohol" [3]=>  string(6) " drunk" [4]=>  string(6) " funny" [5]=>  string(4) " sex" [6]=>  string(8) " machine" } array(7) { [0]=>  string(4) "beer" [1]=>  string(6) " belly" [2]=>  string(8) " alcohol" [3]=>  string(6) " drunk" [4]=>  string(6) " funny" [5]=>  string(4) " sex" [6]=>  string(8) " machine" } array(7) { [0]=>  string(4) "beer" [1]=>  string(6) " belly" [2]=>  string(8) " alcohol" [3]=>  string(6) " drunk" [4]=>  string(6) " funny" [5]=>  string(4) " sex" [6]=>  string(8) " machine" } array(7) { [0]=>  string(4) "beer" [1]=>  string(6) " belly" [2]=>  string(8) " alcohol" [3]=>  string(6) " drunk" [4]=>  string(6) " funny" [5]=>  string(4) " sex" [6]=>  string(8) " machine" } array(7) { [0]=>  string(4) "beer" [1]=>  string(6) " belly" [2]=>  string(8) " alcohol" [3]=>  string(6) " drunk" [4]=>  string(6) " funny" [5]=>  string(4) " sex" [6]=>  string(8) " machine" } array(7) { [0]=>  string(4) "beer" [1]=>  string(6) " belly" [2]=>  string(8) " alcohol" [3]=>  string(6) " drunk" [4]=>  string(6) " funny" [5]=>  string(4) " sex" [6]=>  string(8) " machine" } array(4) { [0]=>  string(7) "beatles" [1]=>  string(6) " music" [2]=>  string(5) " rock" [3]=>  string(12) " john lennon" } array(4) { [0]=>  string(7) "beatles" [1]=>  string(6) " music" [2]=>  string(5) " rock" [3]=>  string(12) " john lennon" } array(4) { [0]=>  string(7) "beatles" [1]=>  string(6) " music" [2]=>  string(5) " rock" [3]=>  string(12) " john lennon" } array(4) { [0]=>  string(7) "beatles" [1]=>  string(6) " music" [2]=>  string(5) " rock" [3]=>  string(12) " john lennon" } array(2) { [0]=>  string(4) "beer" [1]=>  string(5) " bush" } array(2) { [0]=>  string(4) "beer" [1]=>  string(5) " bush" } array(2) { [0]=>  string(4) "beer" [1]=>  string(5) " idol" } array(2) { [0]=>  string(4) "beer" [1]=>  string(5) " idol" } array(1) { [0]=>  string(0) "" } array(3) { [0]=>  string(6) "orange" [1]=>  string(5) "peach" [2]=>  string(7) "bannana" } array(3) { [0]=>  string(6) "orange" [1]=>  string(5) "peach" [2]=>  string(7) "bannana" } array(3) { [0]=>  string(6) "orange" [1]=>  string(5) "peach" [2]=>  string(7) "bannana" } array(2) { [0]=>  string(4) "beer" [1]=>  string(6) " again" } array(2) { [0]=>  string(4) "beer" [1]=>  string(6) " again" } array(2) { [0]=>  string(4) "moar" [1]=>  string(5) " beer" } array(2) { [0]=>  string(4) "moar" [1]=>  string(5) " beer" } array(1) { [0]=>  string(4) "beer" } array(2) { [0]=>  string(4) "beer" [1]=>  string(6) " irish" } array(2) { [0]=>  string(4) "beer" [1]=>  string(6) " irish" } array(2) { [0]=>  string(4) "beer" [1]=>  string(7) " things" } array(2) { [0]=>  string(4) "beer" [1]=>  string(7) " things" } array(2) { [0]=>  string(4) "beer" [1]=>  string(2) " w" } array(2) { [0]=>  string(4) "beer" [1]=>  string(2) " w" }

Link to comment
Share on other sites

Hmmm. okay.

 

But here's what I think could be done. Can I extract only the required stuffs like the 'apple','mango' strings from this array and make a comma separated array only with these strings and then do a array_unique? I guess that can be done..but I am failry new to php ..so have little clue. Any help regarding this?

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.