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
https://forums.phpfreaks.com/topic/202185-remove-elements-in-array/
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

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 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.  :)

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

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

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, 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.