Skip to content

Instantly share code, notes, and snippets.

@pixelsoul
Last active May 19, 2020 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelsoul/9019370c8c1df07f98ea85f72f0f05d0 to your computer and use it in GitHub Desktop.
Save pixelsoul/9019370c8c1df07f98ea85f72f0f05d0 to your computer and use it in GitHub Desktop.
Remove duplicates from multidimensional array in PHP
<?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