-
-
Save GiancarloJSantos/602d1daa9d957b136fe47532b9940da7 to your computer and use it in GitHub Desktop.
[PHP] Extract unique values of the specified key in a two dimensional array
This file contains hidden or 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 | |
/** | |
* Extract unique values of the specified key in a two dimensional array | |
* | |
* @param array $array | |
* @param mixed $key | |
* @return array | |
*/ | |
function array_unique_deep($array, $key) | |
{ | |
$values = array(); | |
foreach ($array as $k1 => $row) | |
{ | |
foreach ($row as $k2 => $v) | |
{ | |
if ($k2 == $key) | |
{ | |
$values[ $k1 ] = $v; | |
continue; | |
} | |
} | |
} | |
return array_unique($values); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment