wtf php, array_filter() will return an array with gaps in it...

This commit is contained in:
Shish
2024-01-19 18:01:50 +00:00
parent ecb3c642a9
commit 6bde7457e7
2 changed files with 2 additions and 1 deletions

View File

@@ -146,7 +146,7 @@ class Search
/** /**
* Count the number of image results for a given search * Count the number of image results for a given search
* *
* @param string[] $tags * @param list<string> $tags
*/ */
public static function count_images(array $tags = []): int public static function count_images(array $tags = []): int
{ {

View File

@@ -197,6 +197,7 @@ class DanbooruApi extends Extension
$tags = array_filter($tags, static function ($element) { $tags = array_filter($tags, static function ($element) {
return $element !== "*"; return $element !== "*";
}); });
$tags = array_values($tags); // reindex array because count_images() expects a 0-based array
$count = Search::count_images($tags); $count = Search::count_images($tags);
$results = Search::find_images(max($start, 0), min($limit, 100), $tags); $results = Search::find_images(max($start, 0), min($limit, 100), $tags);
} }