Retriving multidimensional array using foreach

I’m using a function getMonthsInRange to get number of months in a date range. Code is as follows:

function getMonthsInRange($startDate, $endDate) {
$months = array();
	while (strtotime($startDate) <= strtotime($endDate)) {
			$months[] = array('year' => date('Y', strtotime($startDate)), 'month' => date('m', strtotime($startDate)), );


return $months;

foreach ($month_array  as $m1) {
foreach ($m1 as $m2) {
	$tds_row = mysql_query("SELECT *,SUM(comm_loop_amount * comm_loop_TDS/100) as tds FROM tbl_commission_loop 
	WHERE MONTH(comm_loop_date) = '".$m2."' AND comm_loop_agnt_id = '".$row['comm_loop_agnt_id']."'");


I copied this code from google but it is not giving month and year in different variables. Can anyone please tell me how to obtain both elements in the array?

You need to be aware that the mysql_* extension which your code uses for connecting to MySQL was Removed from version 7 of PHP, you should now be using either the mysqli_* extension (note the i in it) or PDO

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.