phppup Posted November 12, 2022 Share Posted November 12, 2022 I have a list of items and want to verify that each is unique before doing further processing to the list. Is there a built-in function or simple method to verify this? My thought was to put each item into an array and then create a function to run through each element compared to the entire list, but that seems a bit cumbersome. Any better alternatives? Quote Link to comment https://forums.phpfreaks.com/topic/315527-verify-value-is-unique-in-list/ Share on other sites More sharing options...
Solution Barand Posted November 12, 2022 Solution Share Posted November 12, 2022 $arr = [ 1, 2, 3, 1, 4, 5, 2, 6, ]; $arr2 = array_unique($arr); // to force a unique set of values $arr3 = array_count_values($arr); // to verify they are all unique Quote Link to comment https://forums.phpfreaks.com/topic/315527-verify-value-is-unique-in-list/#findComment-1602521 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.