Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中从数组中删除重复的数组值_Javascript_Php_Arrays - Fatal编程技术网

在javascript中从数组中删除重复的数组值

在javascript中从数组中删除重复的数组值,javascript,php,arrays,Javascript,Php,Arrays,我想从我的数组中删除重复项,并且我的数组是 ArrayTotal All Banks,Total All Banks,Total Domestic Banks,Total Domestic Banks,B2B Bank,B2B Bank,Bank of Montreal,Bank of Montreal,The Bank of Nova Scotia,The Bank of Nova Scotia, 我们想删除重复的条目,我正在php unique_数组中尝试,我也在javas

我想从我的数组中删除重复项,并且我的数组是

        ArrayTotal All Banks,Total All Banks,Total Domestic Banks,Total Domestic Banks,B2B Bank,B2B Bank,Bank of Montreal,Bank of Montreal,The Bank of Nova Scotia,The Bank of Nova Scotia,
我们想删除重复的条目,我正在php unique_数组中尝试,我也在javascript中尝试过

      var uniqueNames = [];
      $.each(names, function(i, el){
      if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
      });

     console.log(uniqueNames) its gave error Unexpected token A
在php中试试这个

$dup=array();
foreach($bname as $k=>$v) {

if( ($kt=array_search($v,$bname))!==false and $k!=$kt )
 { unset($unique[$kt]);  $dup[]=$v; }

}

您应该能够在PHP中使用array_unique执行此操作,如下所示:

// Your existing array
$items = [ "Total All Banks", "Total All Banks", "Total Domestic Banks", "Total Domestic Banks", "B2B Bank", "B2B Bank", "Bank of Montreal", "Bank of Montreal", "The Bank of Nova Scotia", "The Bank of Nova Scotia" ];

// array_unique does the dirty work for you
$noduplicates = array_unique($items);

// results are in $noduplicates
print_r($noduplicates);
在这里,它在PHP中没有数组_unique:

// Your existing array
$items = [ "Total All Banks", "Total All Banks", "Total Domestic Banks", "Total Domestic Banks", "B2B Bank", "B2B Bank", "Bank of Montreal", "Bank of Montreal", "The Bank of Nova Scotia", "The Bank of Nova Scotia" ];

// Our new array for items 
$noduplicates = [];

// Loop through all items in an array
foreach($items as $item) {
    // Check new array to see if it's there
    if(!in_array($item, $noduplicates)) {
        // It's not, so add it
        $noduplicates[] = $item;
    }
}

// results are in $noduplicates
print_r($noduplicates);
这里是Javascript格式的-您不需要使用jQuery执行此任务:

// Your existing array
var items = [ "Total All Banks", "Total All Banks", "Total Domestic Banks", "Total Domestic Banks", "B2B Bank", "B2B Bank", "Bank of Montreal", "Bank of Montreal", "The Bank of Nova Scotia", "The Bank of Nova Scotia" ];

// Our new array for items
var noduplicates = []; 

// Loop through all items in an array
for (var i = 0; i < items.length; i++) {
    // Check new array to see if it's already there
    if(noduplicates.indexOf(items[i]) == -1) {
        // add to the new array
        noduplicates.push(items[i]);
    }
}

// results are in noduplicates
console.log(noduplicates);
//您现有的数组
var项目=[“所有银行总额”、“所有银行总额”、“国内银行总额”、“国内银行总额”、“B2B银行”、“B2B银行”、“蒙特利尔银行”、“蒙特利尔银行”、“新斯科舍银行”、“新斯科舍银行”];
//我们的新项目阵列
变量noduplicates=[];
//循环遍历数组中的所有项
对于(变量i=0;i
小提琴是。试试这个


unique_数组应该可以,你能发布你的php代码吗?有什么问题吗?数组_unique不适用于您?请将代码的格式正确,以便我们提供帮助you@preeti数组_unique()不适用于多维数组。请参阅此链接@ayanarg
array_unique()
可用于多维数组;另请看。我已经试过了,但没有工作。我的阵列是这样的问题:阵列全部银行,全部银行,全部国内银行,全部国内银行,B2B银行,B2B银行,蒙特利尔银行,蒙特利尔银行,新斯科舍银行,新斯科舍银行。你解释清楚了吗
var names = ["Total All Banks","Total All Banks","Total Domestic Banks","Total Domestic Banks","B2B Bank","B2B Bank","Bank of Montreal","Bank of Montreal","The Bank of Nova Scotia","The Bank of Nova Scotia"];
var uniqueNames = [];
$.each(names, function(i, el){
    if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
});
console.log(uniqueNames);