Last active
May 19, 2020 03:40
-
-
Save pixelsoul/9019370c8c1df07f98ea85f72f0f05d0 to your computer and use it in GitHub Desktop.
Remove duplicates from multidimensional array in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = array( | |
array("Github","https://github.com"), | |
array("Pixelsoul","https://pixelsoul.com"), | |
array("Pixelsoul","https://pixelsoul.com"), | |
array("Acertus","https://www.acertusdelivers.com"), | |
array("Github","https://github.com"), | |
array("YouTube","https://youtube.com"), | |
array("Acertus","https://metrogistics.com") | |
); | |
$href = array_unique(array_column($array, 1)); // to get a single level array of just those unique values | |
$href = array_intersect_key($array, $href); // if I wanted the original array with unique | |
var_dump(array_values($href)); // array_values to reset the array keys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment