DazlerD Posted August 5, 2008 Share Posted August 5, 2008 Hi Our servers have just been updated to php version 5.2.6 and we have started to get errors. I have some code that initialises a two dimensional array with dates and hours. We then fill the array and use this to display the info. Here is my code to initialise the array. // Setup Date Array. Start of week is 03082008 for ($wd = 0; $wd < 7; $wd++) { $col_name = date('dmY', mktime(0, 0, 0, date("m",$StartOfWeek) , date("d",$StartOfWeek)+$wd, date("Y",$StartOfWeek))); $a_diary = array($col_name => array("00" => ".", "01" => ".", "02" => ".", "03" => ".", "04" => ".", "05" => ".", "06" => ".", "07" => ".", "08" => ".", "09" => ".", "10" => ".", "11" => ".", "12" => ".", "13" => ".", "14" => ".", "15" => ".", "16" => ".", "17" => ".", "18" => ".", "19" => ".", "20" => ".", "21" => ".", "22" => ".", "23" => ".")); echo '<br>col_name = '.$col_name; echo '<br>$a_diary['.$col_name.']["15"] = '.$a_diary[$col_name]["15"]; } echo '<br>Show diary array for the week'; echo '<br>$a_diary["03082008"]["15"] = '.$a_diary["03082008"]["15"]; echo '<br>$a_diary["04082008"]["15"] = '.$a_diary["04082008"]["15"]; echo '<br>$a_diary["05082008"]["15"] = '.$a_diary["05082008"]["15"]; echo '<br>$a_diary["06082008"]["15"] = '.$a_diary["06082008"]["15"]; echo '<br>$a_diary["07082008"]["15"] = '.$a_diary["07082008"]["15"]; echo '<br>$a_diary["08082008"]["15"] = '.$a_diary["08082008"]["15"]; And here is the output: col_name = 03082008 $a_diary[03082008]["15"] = . col_name = 04082008 $a_diary[04082008]["15"] = . col_name = 05082008 $a_diary[05082008]["15"] = . col_name = 06082008 $a_diary[06082008]["15"] = . col_name = 07082008 $a_diary[07082008]["15"] = . col_name = 08082008 $a_diary[08082008]["15"] = . col_name = 09082008 $a_diary[09082008]["15"] = . Show diary array for the week Notice: Undefined index: 03082008 in \\nas76ent\domains\p\mydomain.co.uk\user\htdocs\folder\date.php on line 226 $a_diary["03082008"]["15"] = etc etc Is there any reason why the array can be interigated whilst in the for loop but outside the for loop it doesnt find the element? Please help, this is messing with my mind !! lol Thanks Darren Link to comment https://forums.phpfreaks.com/topic/118244-php-arrays/ Share on other sites More sharing options...
vikramjeet.singla Posted August 5, 2008 Share Posted August 5, 2008 what you are doing is overriding the value $a_diary each time.... you may try this: // Setup Date Array. Start of week is 03082008 for ($wd = 0; $wd < 7; $wd++) { $col_name = date('dmY', mktime(0, 0, 0, date("m",$StartOfWeek) , date("d",$StartOfWeek)+$wd, date("Y",$StartOfWeek))); $a_diary[$col_name] = array("00" => ".", "01" => ".", "02" => ".", "03" => ".", "04" => ".", "05" => ".", "06" => ".", "07" => ".", "08" => ".", "09" => ".", "10" => ".", "11" => ".", "12" => ".", "13" => ".", "14" => ".", "15" => ".", "16" => ".", "17" => ".", "18" => ".", "19" => ".", "20" => ".", "21" => ".", "22" => ".", "23" => "."); echo '<br>col_name = '.$col_name; echo '<br>$a_diary['.$col_name.']["15"] = '.$a_diary[$col_name]["15"]; } echo '<br>Show diary array for the week'; echo '<br>$a_diary["03082008"]["15"] = '.$a_diary["03082008"]["15"]; echo '<br>$a_diary["04082008"]["15"] = '.$a_diary["04082008"]["15"]; echo '<br>$a_diary["05082008"]["15"] = '.$a_diary["05082008"]["15"]; echo '<br>$a_diary["06082008"]["15"] = '.$a_diary["06082008"]["15"]; echo '<br>$a_diary["07082008"]["15"] = '.$a_diary["07082008"]["15"]; echo '<br>$a_diary["08082008"]["15"] = '.$a_diary["08082008"]["15"]; Link to comment https://forums.phpfreaks.com/topic/118244-php-arrays/#findComment-608538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.