fork download
  1. <?php
  2.  
  3. $texto =
  4. 'ID|NOME|TELEFONE0|ENDERECO|REFERENCIA-
  5. ID|NOME|TELEFONE1|ENDERECO|REFERENCIA-
  6. ID|NOME|TELEFONE2|ENDERECO|REFERENCIA-
  7. ID|NOME|TELEFONE0|ENDERECO|REFERENCIA';
  8.  
  9. $item = explode("-", $texto);
  10.  
  11. $items = array_map(function($line)
  12. {
  13. return explode("|", $line);
  14. }, $item);
  15.  
  16. $repeat = [];
  17.  
  18. foreach($items as $it)
  19. {
  20. $repeat[$it[2]] =
  21. isset($repeat[$it[2]])
  22. ? (++$repeat[$it[2]])
  23. : 1;
  24. }
  25.  
  26. $select = array_filter($repeat, function($item){
  27. return $item > 1;
  28. });
  29.  
  30. echo '<pre>';
  31. print_r($repeat);
  32. print_r($select);
  33. echo '<pre>';
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
<pre>Array
(
    [TELEFONE0] => 2
    [TELEFONE1] => 1
    [TELEFONE2] => 1
)
Array
(
    [TELEFONE0] => 2
)
<pre>