PHP highlight duplicate values in array -


this question has answer here:

ok pretty sure there simple solution, , missing on but

lets have simple array:

array (     [0] => 79990     [1] => 79040     [2] => 79100     [3] => 79990     [4] => 79490     [5] => 79290     [6] => 79990 ) 

0, 3 , 6 same value

how mark/highlight these values on foreach loop? result should like:

array (     [0] => *79990*     [1] => 79040     [2] => 79100     [3] => *79990*     [4] => 79490     [5] => 79290     [6] => *79990* ) 

edit: typos

this should trick:

<?php      $array = array( '79900',                     '79040',                     '79100',                     '79990',                     '79490',                     '79290',                     '79990');      $count = array_count_values($array);      echo "<pre>".print_r($array, true)."</pre>";      foreach($array $val)     {         if($count[$val]>1) {             $output[] = "*".$val."*";         } else {             $output[] = $val;         }     }      echo "<pre>".print_r($output, true)."</pre>";  ?> 

outputs:

array (     [0] => 79900     [1] => 79040     [2] => 79100     [3] => 79990     [4] => 79490     [5] => 79290     [6] => 79990 )  array (     [0] => 79900     [1] => 79040     [2] => 79100     [3] => *79990*     [4] => 79490     [5] => 79290     [6] => *79990* ) 

note: [0] isn't same [3] , [6], i'm assuming typo

let me know how on!


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -