Jump to content

remove elements in array


corics15

Recommended Posts

hello everyone!

i have two arrays, for simplicity i have an example:

 

first array:
Array
(
    [0] => 370
    [1] => 368
    [2] => 424
    [3] => 496
    [4] => 307
)

second array:
Array
(
    [0] => 368
    [1] => 496
)

all i want is, remove the elements on the first array based from the second array, thus having:

final array:
Array
(
    [0] => 370
    [2] => 424
    [4] => 307
)

...please help me out...thanks...

Link to comment
Share on other sites

Go with array_diff as AlexWD says.

array_intersect will return what is found that matches the values of the second array. Not what you want.

in_array will only return a single key of the found value. Not what you want.

Note on array diff. It will diff multiple values. If you have the value of say"6" in 3 separate elements you will catch them all.

 

 

HTH

Teamatomic

Link to comment
Share on other sites

thanks for all your help! i went for MatthewJ suggestion! and now it's working perfectly just like i want it!  ;D

 

cheers to this forum!

 

wrong choice you should have gone for AlexWD's solution. It's stupid to write something that is already built-in.

 

thanks ignace..no need to get furious. i also did AlexWD's solution.  :)

Link to comment
Share on other sites

I wasn't furious (bare in mind I'm not a native English speaker) I just pointed out that there is no need to write a function for something that already exists like when someone writes a function to get the extension of a filename instead of using pathinfo

 

lol, until recently i never even knew what basename() did. I'd split my urls into arrays and reverse em and take the first element as a new string. There are such useful inbuilt functions

Link to comment
Share on other sites

lol, until recently i never even knew what basename() did. I'd split my urls into arrays and reverse em and take the first element as a new string. There are such useful inbuilt functions

 

Yeah like end which you clearly don't know either ;)

 

lol, thats also quite embarrasing XD

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.