简体   繁体   中英

Check all values in an array by using a loop PHP

I have an array

Array
(
    [0] => 123
    [1] => 1244
    [2] => 34124
    [3] => 123
)

is there a loop that will check if the values in my array are equal to each other?

this will give you the count of each value

$array = array("123", "1244","34124","123");

$cnt_array = array_count_values($array)

echo "<pre>"; 
print_r($cnt_array);

$res = array();
foreach($cnt_array as $key=>$val){
   if($val == 1){
      $res[$key] = 'unique';
   }
   else{
      $res[$key] = 'duplicate';
   }
}

echo "<pre>";
print_r($res);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM