Skip to content
Advertisement

How to reset indexes in array_diff result?

I have two arrays: Array ( [0] => 2 [1] => 3 ) and Array ( [0] => 2 ).

I want to get the value, which is not in second array. So I have used the array_diff function but my result will get Array ( [1] => 3 )
Actually this is the result. But a small problem here, its position is (key) 1. I want the result in to a new array starts from 0th position, i.e., Array ( [0] => 3 ).

How can I achieve this?

Advertisement

Answer

you can use array_values(array_diff($arr1, $arr2)); if order doesn’t matter

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement