From 687b2e2bc71ec5e7101d2bbd099048b1d0b86c36 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 23 May 2021 19:58:15 +0000 Subject: [PATCH] [UTIL] Add utility to flatten the result of note queries --- src/Util/Common.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Util/Common.php b/src/Util/Common.php index 73be90eaa5..afa2fcca29 100644 --- a/src/Util/Common.php +++ b/src/Util/Common.php @@ -267,4 +267,19 @@ abstract class Common return filter_var($url, FILTER_VALIDATE_URL) && preg_match($regex, parse_url($url, PHP_URL_SCHEME)); } + + /** + * Flatten an array of ['note' => note, 'replies' => [notes]] to an array of notes + */ + public static function flattenNoteArray(array $a): array + { + $notes = []; + foreach ($a as $n) { + $notes[] = $n['note']; + if (isset($n['replies'])) { + $notes = array_merge($notes, static::flattenNoteArray($n['replies'])); + } + } + return $notes; + } }