Answers for "merge arrays php remove duplicates"

PHP
18

php remove duplicates from array

<?php
$fruits_list = array('Orange',  'Apple', ' Banana', 'Cherry', ' Banana');
$result = array_unique($fruits_list);
print_r($result);
?>
  
Output:

Array ( [0] => Orange [1] => Apple [2] => Banana [3] => Cherry )
Posted by: Guest on March-04-2020
1

php remove duplicates from array

<?php
$a=array("a"=>"red","b"=>"green","c"=>"red");
print_r(array_unique($a));
?>
Output : Array ( [a] => red [b] => green )

Example 2:


$array = array(1, 2, 2, 3);
$array = array_unique($array); 
Output : Array is now (1, 2, 3)
Posted by: Guest on March-18-2021
0

php combine 2 arrays keep duplicates

$arrKeys = array('str', 'str', 'otherStr');
$arrVals = array('1.22', '1.99', '5.17');
function foo($key, $val) {
   return array($key=>$val);
}

$arrResult = array_map('foo', $arrKeys, $arrVals);
Posted by: Guest on August-17-2020

Browse Popular Code Answers by Language