From d8b0423d152ca27682b001f2c4d386d9c5dd361e Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 27 Nov 2016 15:44:45 -0500 Subject: Add suggest menu for user mentions in text editor --- app/functions.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'app/functions.php') diff --git a/app/functions.php b/app/functions.php index 8f0d482c..e732f308 100644 --- a/app/functions.php +++ b/app/functions.php @@ -52,6 +52,37 @@ function array_column_index(array &$input, $column) return $result; } +/** + * Create indexed array from a list of dict with unique values + * + * $input = [ + * ['k1' => 1, 'k2' => 2], ['k1' => 3, 'k2' => 4], ['k1' => 1, 'k2' => 5] + * ] + * + * array_column_index_unique($input, 'k1') will returns: + * + * [ + * 1 => ['k1' => 1, 'k2' => 2], + * 3 => ['k1' => 3, 'k2' => 4], + * ] + * + * @param array $input + * @param string $column + * @return array + */ +function array_column_index_unique(array &$input, $column) +{ + $result = array(); + + foreach ($input as &$row) { + if (isset($row[$column]) && ! isset($result[$row[$column]])) { + $result[$row[$column]] = $row; + } + } + + return $result; +} + /** * Sum all values from a single column in the input array * -- cgit v1.2.3