You should be able to do it in PHP with array_unique, like so:
// 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);
Here it is in PHP without 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" ];
// 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);
Here it is in Javascript - you don't need to use jQuery for this task:
// 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);
Fiddle is available here.