[UTIL] Add utility to flatten the result of note queries

This commit is contained in:
Hugo Sales 2021-05-23 19:58:15 +00:00
parent 74f477489b
commit 687b2e2bc7
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 15 additions and 0 deletions

View File

@ -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;
}
}