Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring startdate and enddate values from a function to an array
    primarykey
    data
    text
    <p>Can someone help me in storing startdate and enddate from a function to an array for further processing.</p> <p>Below php code will give start and end dates of each month for a given period. But I am unable to put these values into an array from the function.</p> <p>PHP code:</p> <pre><code> &lt;?php //Function to return out start and end dates of all months in a date range given function rent_range($start_date, $end_date) { $start_date = date("m/d/Y", strtotime($start_date)); $end_date = date("m/d/Y", strtotime($end_date)); $start = strtotime($start_date); $end = strtotime($end_date); $month = $start; $months[] = date('Y-m', $start); while($month &lt; $end) { $month = strtotime("+1 month", $month); $months[] = date('Y-m', $month); } foreach($months as $mon) { $mon_arr = explode( "-", $mon); $y = $mon_arr[0]; $m = $mon_arr[1]; $start_dates_arr[] = date("m/d/Y", strtotime($m.'/01/'.$y.' 00:00:00')); $end_dates_arr[] = date("m/d/Y", strtotime('-1 minute', strtotime('+1 month',strtotime($m.'/01/'.$y.' 00:00:00')))); } //to remove first month in start date and add our start date as first date array_shift($start_dates_arr); array_pop($start_dates_arr); array_unshift($start_dates_arr, $start_date); //To remove last month in end date and add our end date as last date array_pop($end_dates_arr); array_pop($end_dates_arr); array_push($end_dates_arr, $end_date); $result['start_dates'] = $start_dates_arr; $result['end_dates'] = $end_dates_arr; return $result; } $start_date = '2013-04-01'; $end_date = '2014-03-31'; $res = rent_range($start_date, $end_date); echo "&lt;pre&gt;"; print_r($res); echo "&lt;/pre&gt;"; for($i=0; $i&lt;11; $i++) { echo $res[$i]."&lt;br&gt;"; } ?&gt; </code></pre> <p>I need the output of the above function to be in an array like this: Desired output:</p> <pre><code> $res[0]='04/01/2013' $res[1]='05/01/2013' - - - - - - $res[11]='03/01/2014' $res[12]='04/30/2013' $res[13]='05/31/2013' - - - - $res[24]='03/31/2014' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload