I have a date range selected from a database. For this specific example, the date is between June 20 - June 29.
I managed to create an array of these dates. However, the date is repeated many times.
My array looks like this:
Array ( [0] => 2013-06-20 [1] => 2013-06-20 [2] => 2013-06-20 [3] => 2013-06-20 [4] => 2013-06-20 [5] => 2013-06-20 [6] => 2013-06-20 [7] => 2013-06-20 [8] => 2013-06-20 [9] => 2013-06-21 [10] => 2013-06-21 [11] => 2013-06-21 [12] => 2013-06-21 [13] => 2013-06-21 [14] => 2013-06-21 [15] => 2013-06-21 [16] => 2013-06-21 [17] => 2013-06-21 [18] => 2013-06-22 [19] => 2013-06-22 [20] => 2013-06-22 [21] => 2013-06-22 [22] => 2013-06-22 [23] => 2013-06-22 [24] => 2013-06-22 [25] => 2013-06-22 [26] => 2013-06-22 [27] => 2013-06-23 [28] => 2013-06-23 [29] => 2013-06-23 [30] => 2013-06-23 [31] => 2013-06-23 [32] => 2013-06-23 [33] => 2013-06-23 [34] => 2013-06-23 [35] => 2013-06-23 [36] => 2013-06-24 [37] => 2013-06-24 [38] => 2013-06-24 [39] => 2013-06-24 [40] => 2013-06-24 [41] => 2013-06-24 [42] => 2013-06-24 [43] => 2013-06-24 [44] => 2013-06-24 [45] => 2013-06-25 [46] => 2013-06-25 [47] => 2013-06-25 [48] => 2013-06-25 [49] => 2013-06-25 [50] => 2013-06-25 [51] => 2013-06-25 [52] => 2013-06-25 [53] => 2013-06-25 [54] => 2013-06-26 [55] => 2013-06-26 [56] => 2013-06-26 [57] => 2013-06-26 [58] => 2013-06-26 [59] => 2013-06-26 [60] => 2013-06-26 [61] => 2013-06-26 [62] => 2013-06-26 [63] => 2013-06-27 [64] => 2013-06-27 [65] => 2013-06-27 [66] => 2013-06-27 [67] => 2013-06-27 [68] => 2013-06-27 [69] => 2013-06-27 [70] => 2013-06-27 [71] => 2013-06-27 [72] => 2013-06-28 [73] => 2013-06-28 [74] => 2013-06-28 [75] => 2013-06-28 [76] => 2013-06-28 [77] => 2013-06-28 [78] => 2013-06-28 [79] => 2013-06-28 [80] => 2013-06-28 [81] => 2013-06-29 [82] => 2013-06-29 [83] => 2013-06-29 [84] => 2013-06-29 [85] => 2013-06-29 [86] => 2013-06-29 [87] => 2013-06-29 [88] => 2013-06-29 [89] => 2013-06-29 )
As you can see from the array, there are 89 instances. But is it only 9 days?
I have a feeling that it has something to do with my for loop.
My PHP code is as follows:
$user_availabilty = $this->vendor_model->get_user_availability($this->get_user_id()); if($user_availabilty) { foreach($user_availabilty as $user_avail) { $start = strtotime($user_avail->user_availablity_startdate); $end = strtotime($user_avail->user_availablity_enddate); $times = array(); for ($i = $start; $i <= $end; $i += 24 * 3600) { for ($j = 9; $j <= 17; $j++) { $times []= date("Ymd", $i); } } }
How to get only 9 instances in my array, not 89?
date php
Stublackett
source share