Increment value in array php -


i trying make function grabs days have events in database user. instance if there 2 events on jan 23, 2013 add jan 23, 2013 array. got work adds days (without adding same day twice) want able how many dates on each day. on jan 23, 2013 have 2 events in day.

i hope makes sense... have code further aid.

php function (grabbing each day has events)

//gets upcoming days have events user     public function get_upcoming_days_with_events() {         $return_array = array();         $date_in=null;         $user_id = $this->session->userdata('id');         $query =$this->db->select()->from('events')->where('user_id', $user_id)->get();         foreach ($query->result_array() $event => $row) {             $date = strtotime($row['date_due']);             if (sizeof($return_array) != 0) {                 foreach ($return_array $date_in_array => $row) {                     $d = $row['full_date'];                     if (date('y-m-d', $date) == $d) {                         //date in array                         //increment number of assignments on day                         $row['number_of_assignments'] += 1;                         $date_in = true;                     } else{                         $date_in = false;                     }                 }             }             if ($date_in == false) {                 $return_array[] = array(                     'day' => date('d', $date),                     'month' => date('m', $date),                     'full_date' => date('y-m-d', $date),                     'number_of_assignments' => 1                 );             }         }         return $return_array;     } 

so want able increment $return_array['number_of_assignments'] if function notices day has more 1 event.

let me know if need more info...

thanks! :)

we can save info in return_array index of date, if date info have not been set return_array, make empty info. each time, increase number_of_assignments.

 public function get_upcoming_days_with_events()  {      $return_array = array();      $user_id = $this->session->userdata('id');      $query =$this->db->select()->from('events')->where('user_id', $user_id)->get();      foreach ($query->result_array() $event => $row)      {          $date = strtotime($row['date_due']);          $date_key = date('y-m-d', $date);          if (!isset($return_array[$date_key]))          {              $new_item = array(                  'day' => date('d', $date),                  'month' => date('m', $date),                  'full_date' => $date_key,                  'number_of_assignments' => 0,              );              $return_array[$date_key] = $new_item;          }          $return_array[$date_key]['number_of_assignments']++;      }      $return_array = array_values($return_array);      return $return_array;  } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -