Accessing values in an array [SOLVED]
Posted: Thu Jan 22, 2009 3:50 pm
i got this code off of php.net
it does exactly what i want it to do but i am having problems accessing a single value in the array
that spits out this
what i want to do is access each value individually. i have tried many different ways but cant seem to get it. does anyone know how i would just output the first value?
i have tried things like
what i want to do is eventually write a query based on the date and pull records for the dates.
thanks
it does exactly what i want it to do but i am having problems accessing a single value in the array
Code: Select all
<?php
$year = '2009';
function getMondays($year) {
$newyear = $year;
$week = 0;
$day = 0;
$mo = 1;
$mondays = array();
$i = 1;
while ($week != 1) {
$day++;
$week = date("w", mktime(0, 0, 0, $mo,$day, $year));
}
array_push($mondays,date("r", mktime(0, 0, 0, $mo,$day, $year)));
while ($newyear == $year) {
$test = strtotime(date("r", mktime(0, 0, 0, $mo,$day, $year)) . "+" . $i . " week");
$i++;
if ($year == date("Y",$test)) {
array_push($mondays,date("r", $test));
}
$newyear = date("Y",$test);
}
return $mondays;
}
print_r (getMondays($year));
?>Code: Select all
Array ( [0] => Mon, 05 Jan 2009 00:00:00 -0600 [1] => Mon, 12 Jan 2009 00:00:00 -0600 [2] => Mon, 19 Jan 2009 00:00:00 -0600 [3] => Mon, 26 Jan 2009 00:00:00 -0600 [4] => Mon, 02 Feb 2009 00:00:00 -0600 [5] => Mon, 09 Feb 2009 00:00:00 -0600 [6] => Mon, 16 Feb 2009 00:00:00 -0600 [7] => Mon, 23 Feb 2009 00:00:00 -0600 [8] => Mon, 02 Mar 2009 00:00:00 -0600 [9] => Mon, 09 Mar 2009 01:00:00 -0500 [10] => Mon, 16 Mar 2009 01:00:00 -0500 [11] => Mon, 23 Mar 2009 01:00:00 -0500 [12] => Mon, 30 Mar 2009 01:00:00 -0500 [13] => Mon, 06 Apr 2009 01:00:00 -0500 [14] => Mon, 13 Apr 2009 01:00:00 -0500 [15] => Mon, 20 Apr 2009 01:00:00 -0500 [16] => Mon, 27 Apr 2009 01:00:00 -0500 [17] => Mon, 04 May 2009 01:00:00 -0500 [18] => Mon, 11 May 2009 01:00:00 -0500 [19] => Mon, 18 May 2009 01:00:00 -0500 [20] => Mon, 25 May 2009 01:00:00 -0500 [21] => Mon, 01 Jun 2009 01:00:00 -0500 [22] => Mon, 08 Jun 2009 01:00:00 -0500 [23] => Mon, 15 Jun 2009 01:00:00 -0500 [24] => Mon, 22 Jun 2009 01:00:00 -0500 [25] => Mon, 29 Jun 2009 01:00:00 -0500 [26] => Mon, 06 Jul 2009 01:00:00 -0500 [27] => Mon, 13 Jul 2009 01:00:00 -0500 [28] => Mon, 20 Jul 2009 01:00:00 -0500 [29] => Mon, 27 Jul 2009 01:00:00 -0500 [30] => Mon, 03 Aug 2009 01:00:00 -0500 [31] => Mon, 10 Aug 2009 01:00:00 -0500 [32] => Mon, 17 Aug 2009 01:00:00 -0500 [33] => Mon, 24 Aug 2009 01:00:00 -0500 [34] => Mon, 31 Aug 2009 01:00:00 -0500 [35] => Mon, 07 Sep 2009 01:00:00 -0500 [36] => Mon, 14 Sep 2009 01:00:00 -0500 [37] => Mon, 21 Sep 2009 01:00:00 -0500 [38] => Mon, 28 Sep 2009 01:00:00 -0500 [39] => Mon, 05 Oct 2009 01:00:00 -0500 [40] => Mon, 12 Oct 2009 01:00:00 -0500 [41] => Mon, 19 Oct 2009 01:00:00 -0500 [42] => Mon, 26 Oct 2009 01:00:00 -0500 [43] => Mon, 02 Nov 2009 00:00:00 -0600 [44] => Mon, 09 Nov 2009 00:00:00 -0600 [45] => Mon, 16 Nov 2009 00:00:00 -0600 [46] => Mon, 23 Nov 2009 00:00:00 -0600 [47] => Mon, 30 Nov 2009 00:00:00 -0600 [48] => Mon, 07 Dec 2009 00:00:00 -0600 [49] => Mon, 14 Dec 2009 00:00:00 -0600 [50] => Mon, 21 Dec 2009 00:00:00 -0600 [51] => Mon, 28 Dec 2009 00:00:00 -0600 )i have tried things like
Code: Select all
$mondays[0]what i want to do is eventually write a query based on the date and pull records for the dates.
thanks