carlozdre Posted November 19, 2013 Share Posted November 19, 2013 I have an array called $lineArray. If I do a var_dump on $lineArray[5] I will get a few hundreds entries, something like: string(9) "something" string(13) "somethingelse" string(9) "notreally" string(9) "something" I need to move/copy all those lines into another array but without the duplicates, so I will only have one 'something' in the new array, not have it twice as per the above example. I've tried: $pagesWithErrors = array(); $pagesWithErrors[] = $lineArray[5]; $pagesWithErrors = array_unique($pagesWithErrors); But it doesn't work for me. How do I do it? Quote Link to comment https://forums.phpfreaks.com/topic/284070-remove-duplicates-in-array/ Share on other sites More sharing options...
Ch0cu3r Posted November 19, 2013 Share Posted November 19, 2013 (edited) You'll want to pass $lineArray[5]; to array_unique $uniqueErrors = array_unique($lineArray[5]); var_dump($uniqueErrors); should display without duplicates Edited November 19, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/284070-remove-duplicates-in-array/#findComment-1459048 Share on other sites More sharing options...
carlozdre Posted November 19, 2013 Author Share Posted November 19, 2013 I get: Warning: array_unique() expects parameter 1 to be array, string given on line xxx (first one). Quote Link to comment https://forums.phpfreaks.com/topic/284070-remove-duplicates-in-array/#findComment-1459057 Share on other sites More sharing options...
Ch0cu3r Posted November 19, 2013 Share Posted November 19, 2013 If I do a var_dump on $lineArray[5] I will get a few hundreds entries That to me suggests$lineArray[5] is an array. Maybe you meant $lineArray is the array. Try array_unique($lineArray); Quote Link to comment https://forums.phpfreaks.com/topic/284070-remove-duplicates-in-array/#findComment-1459063 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.