Count dates inside an array PHP -


i have array :

array ( [0] => array ( [x] => 2016-04-19 )  [1] => array ( [x] => 2016-05-25 )  [2] => array ( [x] => 2016-05-26 )  [3] => array ( [x] => 2016-05-27 )  [4] => array ( [x] => 2016-05-28 )  [5] => array ( [x] => 2016-05-29 )  [6] => array ( [x] => 2016-05-29 )  [7] => array ( [x] => 2016-06-02 )  [8] => array ( [x] => 2016-06-03 )  [9] => array ( [x] => 2016-06-07 )  [10] => array ( [x] => 2016-06-10 )  [11] => array ( [x] => 2016-06-17 )  [12] => array ( [x] => 2016-06-24 ) ) 

i'm trying count how many days duplicates , number in variable. example can see there 2 same dates:

2016-05-29

i've tried array_count_values() says can count strings , integers. that's correct because date variable. it's code:

$eventdates = $object->get("date"); $result = $eventdates->format("y-m-d"); $data[] = array("x"=>$result); 

any idea of how count them?

using array_map can convert dates strings, can use array_count_values:

$thearray = array(array('x' => new datetime('2016-04-19')),      array('x' => new datetime('2016-04-19')),     array('x' => new datetime('2016-04-19')),     array('x' => new datetime('2016-05-19')));  function formatdate($d) {     return $d['x']->format('y-m-d'); } $results = array_map("formatdate", $thearray);  print_r(array_count_values($results)); 

.

array (     [2016-04-19] => 3     [2016-05-19] => 1  ) 

then can use determine duplicates.

(this useful if dates contained time elements wanted ignore.)


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -