Get unique values from multi-dimensional array

837 0 0 0

Last Updated : 2024-04-18 22:29:37

Sometimes you have a multi-dimensional array and you only need the unique arrays in it. here is a simple solution using pure php function

    [0] => Array
(
[id] => 9622779
[title] => First Consultation #2
[description] => First Consultation description#2
[department] => It#2
[jurisdiction] => none
[startDate] => 2021-08-05 00:00:00
[endDate] => 2021-08-07 00:00:00
[hyperlink] => codeexplode2.com
[status] => Y
[tags] => First Consultation,consultations,#2
[created_at] => 2021-08-03 15:00:28
[updated_at] => 2021-08-03 15:29:11
)

[1] => Array
(
[id] => 9622781
[title] => Second consultation
[description] => Second consultation description
[department] => Finance
[jurisdiction] => British Columbia
[startDate] => 2021-08-03 00:00:00
[endDate] => 2021-08-03 00:00:00
[hyperlink] => google.com
[status] => Y
[tags] => first consultation,second,second consultation,quebec
[created_at] => 2021-08-03 16:21:09
[updated_at] => 2021-10-04 13:13:19
)

[2] => Array
(
[id] => 9622779
[title] => First Consultation #2
[description] => First Consultation description#2
[department] => It#2
[jurisdiction] => none
[startDate] => 2021-08-05 00:00:00
[endDate] => 2021-08-07 00:00:00
[hyperlink] => codeexplode2.com
[status] => Y
[tags] => First Consultation,consultations,#2
[created_at] => 2021-08-03 15:00:28
[updated_at] => 2021-08-03 15:29:11
)

[3] => Array
(
[id] => 9622782
[title] => Third Consultation
[description] => Third Consultation description
[department] => Dep#3
[jurisdiction] => none
[startDate] =>
[endDate] =>
[hyperlink] =>
[status] => Y
[tags] => dep3,consultations
[created_at] => 2021-08-04 15:03:29
[updated_at] => 2021-08-04 15:03:29
)

[4] => Array
(
[id] => 9622783
[title] => Fourth Consultation
[description] => Any description here
[department] => Dep4
[jurisdiction] => none
[startDate] => 1970-01-01 00:00:00
[endDate] => 1970-01-01 00:00:00
[hyperlink] => yahoo.com
[status] => Y
[tags] => dep4,consultations
[created_at] => 2021-08-04 15:15:46
[updated_at] => 2021-08-04 15:15:58
)

[5] => Array
(
[id] => 9622784
[title] => Fifth consultation
[description] => Fifth consultation description
[department] => fifth
[jurisdiction] => none
[startDate] => 2021-08-01 00:00:00
[endDate] => 2021-08-08 00:00:00
[hyperlink] => http://www.codeexplode.com
[status] => Y
[tags] => fifth,consultations
[created_at] => 2021-08-08 07:15:17
[updated_at] => 2021-08-08 07:15:17
)

[6] => Array
(
[id] => 9622785
[title] => Fifth consultation2
[description] => Fifth consultation description2
[department] => fifth
[jurisdiction] => none
[startDate] => 2021-08-01 00:00:00
[endDate] => 2021-08-08 00:00:00
[hyperlink] => http://www.codeexplode.com
[status] => Y
[tags] => fifth,consultations
[created_at] => 2021-08-08 07:17:10
[updated_at] => 2021-08-08 07:17:10
)

[7] => Array
(
[id] => 9622786
[title] => Fifth consultation23
[description] => Fifth consultation description23
[department] => fifth
[jurisdiction] => none
[startDate] => 2021-08-01 00:00:00
[endDate] => 2021-08-08 00:00:00
[hyperlink] => http://www.codeexplode.com
[status] => Y
[tags] => fifth,consultations
[created_at] => 2021-08-08 07:17:51
[updated_at] => 2021-08-08 07:17:51
)

[8] => Array
(
[id] => 9622787
[title] => Fifth consultation234
[description] => Fifth consultation description234
[department] => fifth
[jurisdiction] => none
[startDate] => 2021-08-01 00:00:00
[endDate] => 2021-08-08 00:00:00
[hyperlink] => http://www.codeexplode.com
[status] => Y
[tags] => fifth,consultations
[created_at] => 2021-08-08 07:18:23
[updated_at] => 2021-08-08 07:18:23
)

[9] => Array
(
[id] => 9622788
[title] => Fifth consultation2345
[description] => Fifth consultation description2345
[department] => fifth
[jurisdiction] => none
[startDate] => 2021-08-01 00:00:00
[endDate] => 2021-08-08 00:00:00
[hyperlink] => http://www.codeexplode.com
[status] => Y
[tags] => fifth,consultations
[created_at] => 2021-08-08 07:19:43
[updated_at] => 2021-08-08 07:19:43
)

[10] => Array
(
[id] => 9622789
[title] => Fifth consultation23456
[description] => Fifth consultation description23456
[department] => fifth
[jurisdiction] => Nfld. & Labrador
[startDate] => 2021-08-01 00:00:00
[endDate] => 2021-08-08 00:00:00
[hyperlink] => http://www.codeexplode.com
[status] => Y
[tags] => fifth,consultations,boody
[created_at] => 2021-08-08 07:22:34
[updated_at] => 2021-08-25 14:37:14
)

[11] => Array
(
[id] => 9622790
[title] => Six consultation
[description] => Six consultation description
[department] => six
[jurisdiction] => none
[startDate] => 2021-08-01 00:00:00
[endDate] => 2021-08-08 00:00:00
[hyperlink] => http://www.codeexplode.com
[status] => Y
[tags] => six,consultations
[created_at] => 2021-08-08 08:17:30
[updated_at] => 2021-08-08 08:17:30
)

[12] => Array
(
[id] => 9622791
[title] => The new consultation
[description] => Here the description for it
[department] => IT
[jurisdiction] => none
[startDate] => 2021-08-08 00:00:00
[endDate] => 2021-08-09 00:00:00
[hyperlink] => http://www.codeexplode.com
[status] => Y
[tags] => it,consultations
[created_at] => 2021-08-08 09:47:06
[updated_at] => 2021-08-08 09:47:06
)

[13] => Array
(
[id] => 9622795
[title] => Consultation test for tags#10
[description] => Consultation test for tags#10
[department] => Consultations
[jurisdiction] => Alberta
[startDate] => 2021-09-11 00:00:00
[endDate] => 2021-09-11 00:00:00
[hyperlink] => http://www.testtags.com
[status] => Y
[tags] => consultations,consultationsTags#10
[created_at] => 2021-09-11 10:05:38
[updated_at] => 2021-09-11 10:05:38
)

[14] => Array
(
[id] => 9622796
[title] => Consultation test for tags#10 1
[description] => Consultation test for tags#10
[department] => Consultations
[jurisdiction] => Alberta
[startDate] => 2021-09-11 00:00:00
[endDate] => 2021-09-11 00:00:00
[hyperlink] => http://www.testtags.com
[status] => Y
[tags] => consultations,consultationsTags#10
[created_at] => 2021-09-11 10:06:52
[updated_at] => 2021-09-11 10:06:52
)

[15] => Array
(
[id] => 9622797
[title] => Consultation test for tags#10 2
[description] => Consultation test for tags#10
[department] => Consultations
[jurisdiction] => British Columbia
[startDate] => 2021-09-11 00:00:00
[endDate] => 2021-09-10 00:00:00
[hyperlink] =>
[status] => Y
[tags] => consultationstags#10,consultation#11
[created_at] => 2021-09-11 10:55:39
[updated_at] => 2021-09-11 10:55:39
)

[16] => Array
(
[id] => 9622797
[title] => Consultation test for tags#10 2
[description] => Consultation test for tags#10
[department] => Consultations
[jurisdiction] => British Columbia
[startDate] => 2021-09-11 00:00:00
[endDate] => 2021-09-10 00:00:00
[hyperlink] =>
[status] => Y
[tags] => consultationstags#10,consultation#11
[created_at] => 2021-09-11 10:55:39
[updated_at] => 2021-09-11 10:55:39
)

[17] => Array
(
[id] => 9622798
[title] => Test for Quebec
[description] => Description for Quenbec
[department] => Quebec
[jurisdiction] => Ontario
[startDate] => 2021-10-04 00:00:00
[endDate] => 2021-10-05 00:00:00
[hyperlink] => http://www.chpc.com
[status] => Y
[tags] => immigration,mobile,quebec,Quebec
[created_at] => 2021-10-04 12:06:04
[updated_at] => 2021-10-04 13:09:59
)

[18] => Array
(
[id] => 9622799
[title] => Test for immigration
[description] => Descriptioin for immigration
[department] => Immigration
[jurisdiction] => Quebec
[startDate] => 2021-10-04 00:00:00
[endDate] => 2021-10-05 00:00:00
[hyperlink] => http://www.chpc.com
[status] => Y
[tags] => immigration
[created_at] => 2021-10-04 12:45:04
[updated_at] => 2021-10-04 12:45:04
)

[19] => Array
(
[id] => 9622781
[title] => Second consultation
[description] => Second consultation description
[department] => Finance
[jurisdiction] => British Columbia
[startDate] => 2021-08-03 00:00:00
[endDate] => 2021-08-03 00:00:00
[hyperlink] => google.com
[status] => Y
[tags] => first consultation,second,second consultation,quebec
[created_at] => 2021-08-03 16:21:09
[updated_at] => 2021-10-04 13:13:19
)

[20] => Array
(
[id] => 9622798
[title] => Test for Quebec
[description] => Description for Quenbec
[department] => Quebec
[jurisdiction] => Ontario
[startDate] => 2021-10-04 00:00:00
[endDate] => 2021-10-05 00:00:00
[hyperlink] => http://www.chpc.com
[status] => Y
[tags] => immigration,mobile,quebec,Quebec
[created_at] => 2021-10-04 12:06:04
[updated_at] => 2021-10-04 13:09:59
)

)

$allUserConsultationsNew = array_unique($allUserConsultations->toArray(), SORT_REGULAR);

Mohammed Anwar

Mohammed Anwar

Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .