3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $arr=Array(Array("segments" => Array(1=>"Gcia de Auditoría Interna",0 => "Auditoria Interna 1"),"groups" => Array("estados" => "sp","cidade" => "sumpaulo")), Array("segments" => Array(2 => "Gerencia Recursos Humanos",1 => "Gcia Dpto Admin de Pers. y Rel. Laboral",0 => "SubGcia Administración de Personal"),"groups" => Array("estados" => "sp","cidade" => "")), Array("segments" => Array(2 => "Gerencia Recursos Humanos",1 => "Gcia Dpto Admin de Pers. y Rel. Laboral",0 => "SubGcia Administración de Personal"),"groups" => Array("estados" => "sp","cidade" => ""))); $rst=array(); foreach($arr as $ele) { foreach($rst as $i=>$candidate) { $key=null; foreach($ele as $k=>$subarr) { if(isset($candidate[$k]) && $candidate[$k]==$subarr) { $key=$i; break; } } if(!empty($key)) { break; } } if(!empty($key)) $rst[$key]["total"]+=1; else $rst[]=array_merge($ele,array("total"=>1)); } print_r($rst);
Output for 4.3.0 - 7.1.0
Array ( [0] => Array ( [segments] => Array ( [1] => Gcia de Auditoría Interna [0] => Auditoria Interna 1 ) [groups] => Array ( [estados] => sp [cidade] => sumpaulo ) [total] => 1 ) [1] => Array ( [segments] => Array ( [2] => Gerencia Recursos Humanos [1] => Gcia Dpto Admin de Pers. y Rel. Laboral [0] => SubGcia Administración de Personal ) [groups] => Array ( [estados] => sp [cidade] => ) [total] => 2 ) )