Skip to content

Instantly share code, notes, and snippets.

@mistic100
Last active January 25, 2020 12:14
Show Gist options
  • Save mistic100/8356974 to your computer and use it in GitHub Desktop.
Save mistic100/8356974 to your computer and use it in GitHub Desktop.
[PHP] Extract unique values of the specified key in a two dimensional array
<?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