1<?php
2$fruits_list = array('Orange', 'Apple', ' Banana', 'Cherry', ' Banana');
3$result = array_unique($fruits_list);
4print_r($result);
5?>
6
7Output:
8
9Array ( [0] => Orange [1] => Apple [2] => Banana [3] => Cherry )
1
2<?php
3$input = array("a" => "green", "red", "b" => "green", "blue", "red");
4$result = array_unique($input);
5print_r($result);
6?>
7
8Array
9(
10 [a] => green
11 [0] => red
12 [1] => blue
13)
1<?php
2$list_programming_language = array('C#', 'C++', 'PHP', 'C#', 'PHP');
3$result = array_unique($list_programming_language);
4print_r($result);
5?>
6
7// ==> 'C#', 'C++', 'PHP'
1<?php
2$a=array("a"=>"red","b"=>"green","c"=>"red");
3print_r(array_unique($a));
4?>
5Output : Array ( [a] => red [b] => green )
6
7Example 2:
8
9
10$array = array(1, 2, 2, 3);
11$array = array_unique($array);
12Output : Array is now (1, 2, 3)
13
14
1<?php
2$fruits_list = array('Orange', 'Apple', ' Banana', 'Cherry', ' Banana');
3$result = array_unique($fruits_list);
4print_r($result);
5?>