fork download
  1. <?php
  2. $arr = array(
  3. 'id' => '147',
  4. 'nome' =>'João',
  5. 'email' => 'joao@teste.com',
  6. 'data_nascimento' => '05/01/1987',
  7. 'numero_1' => '1',
  8. 'rua_1' => 'rua 1',
  9. 'numero_2' => '2',
  10. 'rua_2' => 'rua 2',
  11. 'submit' => 'Salvar'
  12. );
  13. $newArr = array();
  14. foreach ($arr as $k => $v) {
  15. $partes = explode("_", $k);
  16. if (count($partes) > 1) {
  17. $repetido = 0;
  18. foreach ($arr as $k2 => $v2) {
  19. if (strpos($k2, $partes[0]."_") === 0) {
  20. $repetido++;
  21. }
  22. }
  23. if ($repetido > 1)
  24. $newArr[$k] = $v;
  25. }
  26. }
  27. var_dump($newArr);
  28.  
  29. //https://pt.stackoverflow.com/q/40557/101
Success #stdin #stdout 0.02s 82560KB
stdin
Standard input is empty
stdout
array(4) {
  ["numero_1"]=>
  string(1) "1"
  ["rua_1"]=>
  string(5) "rua 1"
  ["numero_2"]=>
  string(1) "2"
  ["rua_2"]=>
  string(5) "rua 2"
}