PHP unique array function for nested array

Is there a way to use the Array_unique function to work with a nested array, as shown below? I want to get rid of duplicate dates and get two dates as an array ...

Array ( [0] => Array ( [value] => 1311044688 [name] => 19th Jul 2011 ) [1] => Array ( [value] => 1311044919 [name] => 19th Jul 2011 ) [2] => Array ( [value] => 1311045076 [name] => 19th Jul 2011 ) [3] => Array ( [value] => 1311164873 [name] => 20th Jul 2011 ) [4] => Array ( [value] => 1311165000 [name] => 20th Jul 2011 ) ) 
+3
source share
2 answers

I would write this array to another array using date as keys, and "values" as value. This is probably the fastest way to get what you are looking for.

Sort of:

 $uniqueAry = array() foreach ($ary as $item) { $uniqueAry[$item['name']] = $item['value']; } 

You probably want to turn on the logic bit to determine what value takes precedence in case of cheating.

+5
source

You can create an array of dates and then use array_unique in the date array.

0
source

Source: https://habr.com/ru/post/944206/


All Articles