replace array_{add,remove} with array_diff
This commit is contained in:
parent
deb26ff7d3
commit
43ea7fb70c
@ -3,35 +3,6 @@
|
||||
* Things which should be in the core API *
|
||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/**
|
||||
* Remove an item from an array
|
||||
*/
|
||||
function array_remove(array $array, $to_remove): array
|
||||
{
|
||||
$array = array_unique($array);
|
||||
$a2 = [];
|
||||
foreach ($array as $existing) {
|
||||
if ($existing != $to_remove) {
|
||||
$a2[] = $existing;
|
||||
}
|
||||
}
|
||||
return $a2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item to an array.
|
||||
*
|
||||
* Also removes duplicate values from the array.
|
||||
*/
|
||||
function array_add(array $array, $element): array
|
||||
{
|
||||
// Could we just use array_push() ?
|
||||
// http://www.php.net/manual/en/function.array-push.php
|
||||
$array[] = $element;
|
||||
$array = array_unique($array);
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the unique elements of an array, case insensitively
|
||||
*/
|
||||
|
@ -227,7 +227,7 @@ class TagListTheme extends Themelet
|
||||
$display_html = '';
|
||||
$tag = $row['tag'];
|
||||
$h_tag = html_escape($tag);
|
||||
|
||||
|
||||
$tag_category_css = '';
|
||||
$tag_category_style = '';
|
||||
$h_tag_split = explode(':', html_escape($tag), 2);
|
||||
@ -277,8 +277,7 @@ class TagListTheme extends Themelet
|
||||
if (!in_array($tag, $tags) && !in_array("-$tag", $tags)) {
|
||||
return "";
|
||||
} else {
|
||||
$tags = array_remove($tags, $tag);
|
||||
$tags = array_remove($tags, "-$tag");
|
||||
$tags = array_diff($tags, [$tag, "-$tag"]);
|
||||
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Remove' rel='nofollow'>R</a>";
|
||||
}
|
||||
}
|
||||
@ -288,8 +287,7 @@ class TagListTheme extends Themelet
|
||||
if (in_array($tag, $tags)) {
|
||||
return "";
|
||||
} else {
|
||||
$tags = array_remove($tags, "-$tag");
|
||||
$tags = array_add($tags, $tag);
|
||||
$tags = array_diff($tags, ["-$tag"]) + [$tag];
|
||||
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Add' rel='nofollow'>A</a>";
|
||||
}
|
||||
}
|
||||
@ -299,8 +297,7 @@ class TagListTheme extends Themelet
|
||||
if (in_array("-$tag", $tags)) {
|
||||
return "";
|
||||
} else {
|
||||
$tags = array_remove($tags, $tag);
|
||||
$tags = array_add($tags, "-$tag");
|
||||
$tags = array_diff($tags, [$tag]) + ["-$tag"];
|
||||
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Subtract' rel='nofollow'>S</a>";
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user