我在PHP中需要像这样的数组吗?
array = [mani , mani, nithi, nithi, basto]
return in
array = [basto]
not for other elements
有人知道如何解决这个问题吗?
答案 0 :(得分:1)
您可能想指定您的问题,以便此处的用户提供更好的帮助。
针对您的问题:
array_unique($array);
https://www.php.net/manual/en/function.array-unique.php
编辑:您要按名称搜索所有项目,为此需要此功能:https://www.php.net/manual/en/function.array-search.php
以您的示例为例:
$array = ['mani' , 'mani', 'nithi', 'nithi', 'basto'];
$basto = array_search('basto', $array);
最佳,
Sebo
答案 1 :(得分:1)
vec <- rep(ovec, 10000)
# Unit: milliseconds
# expr min lq mean median uq max neval
# base 99.1428 101.35455 111.49082 106.3730 119.97595 183.0905 100
# lub 36.0184 37.09255 42.45397 40.2352 46.85875 74.5182 100
输出:
<?php
$items = ['mani' , 'mani', 'nithi', 'nithi', 'basto'];
$counts = array_count_values($items);
// Remove elements that occur more than once.
$filtered = array_filter($items, function ($item) use ($counts) {
return $counts[$item] === 1;
});
var_export($filtered);