3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $result = array(); $list = array( 0 => array( "rut" => "16.534.770-6", "nombre" => "Miguel Pichipillán S", "fecha" => "25/08/2015", "estado" => "M/Ent", "count_ent" => 0, "count_sal" => 0 ), 1 => array( "rut" => "16.534.770-6", "nombre" => "Miguel Pichipillán S", "fecha" => "25/08/2015", "estado" => "M/Sal", "count_ent" => 0, "count_sal" => 0 ), 2 => array( "rut" => "16.534.770-6", "nombre" => "Miguel Pichipillán S", "fecha" => "26/08/2015", "estado" => "M/Ent", "count_ent" => 0, "count_sal" => 0 ), 3 => array( "rut" => "16.534.770-6", "nombre" => "Miguel Pichipillán S", "fecha" => "26/08/2015", "estado" => "M/Sal", "count_ent" => 0, "count_sal" => 0 ), 4 => array( "rut" => "16.534.770-6", "nombre" => "Miguel Pichipillán S", "fecha" => "26/08/2015", "estado" => "M/Ent", "count_ent" => 0, "count_sal" => 0 ), 5 => array( "rut" => "16.534.770-6", "nombre" => "Miguel Pichipillán S", "fecha" => "26/08/2015", "estado" => "M/Sal", "count_ent" => 0, "count_sal" => 0 ), 22 => array( "rut" => "16.534.770-6", "nombre" => "Miguel Pichipillán S", "fecha" => "02/09/2015", "estado" => "M/Ent", "count_ent" => 0, "count_sal" => 0 ), 23 => array( "rut" => "16.534.770-6", "nombre" => "Miguel Pichipillán S", "fecha" => "02/09/2015", "estado" => "M/Ent", "count_ent" => 0, "count_sal" => 0 ), 24 => array( "rut" => "16.534.770-6", "nombre" => "Miguel Pichipillán S", "fecha" => "02/09/2015", "estado" => "M/Ent", "count_ent" => 0, "count_sal" => 0 ), 25 => array( "rut" => "16.534.770-6", "nombre" => "Miguel Pichipillán S", "fecha" => "02/09/2015", "estado" => "M/Sal", "count_ent" => 0, "count_sal" => 0 ), ); foreach ($list as $key => $value) { $estado = $value["estado"]; $fecha = $value["fecha"]; unset($value["estado"]); if (!isset($result[$fecha])) { $result[$fecha] = $value; } if ($estado === "M/Sal") { $result[$fecha]["count_sal"]++; } if ($estado === "M/Ent") { $result[$fecha]["count_ent"]++; } } foreach ($result as $k => $v) { if ($v["count_ent"] === 2 && $v["count_sal"] === 2) { continue; } unset ($result[$k]); } var_dump($result);
Output for 5.3.20 - 7.2.0
array(1) { ["26/08/2015"]=> array(5) { ["rut"]=> string(12) "16.534.770-6" ["nombre"]=> string(21) "Miguel Pichipillán S" ["fecha"]=> string(10) "26/08/2015" ["count_ent"]=> int(2) ["count_sal"]=> int(2) } }