I have a function that I am writing to take in values datetime values from an array and convert it into hours and minutes format like 0010. I want to use this to later extract other values from the array as this is an associative array
function getData($lengthArray, $csvdat) { # passing down the values of the array and the length of the array $newData = array( 'nightTime1', 'nightTime2', 'dayTime1', 'peakTime', 'dayTime2', 'winterNightTime1', 'winterNightTime2', 'winterDayTime1', 'winterDayTime2', 'winterPeakTime'); for ($count = 0; $count <= $lengthArray; $count++ ) { #looping to the length of the array $arrayTimestamp = $csvdat[$count]['timestamp']; $comparator = date('Hs', strtotime($arrayTimestamp)); #extracting the time format $nightTime1 = 0759; $dayTime1 = 1659; $peakTime = 1859; $dayTime2 = 2259; $nightTime2 = 2359; if ( $comparator == $nightTime1 ) { if (empty($newData['nightTime1'])) { $newData['nightTime1'] = $nightTime; $newData['nightTime1']['phase1'] = $csvdat[$count++]['day_chan1']; $newData['nightTime1']['phase1'] = $csvdat[$count++]['day_chan2']; $newData['nightTime1']['phase1'] = $csvdat[$count++]['day_chan3']; } else if (!empty($newData)) { } } } return $newData; } getData($lengthData , $csvdata); var_dump($newData); The problem I am facing now is that I get an Undefined offset error at the line
$arrayTimestamp = $csvdat[$count]['timestamp']; and an undefined variable for $newData. I am not very good at php so please advise.
Here is the var_dump of the csvdat array
array (size=118061) 0 => array (size=15) 'timestamp' => string '01/02/2014 00:00' (length=16) 'curr_property' => string '5972' (length=4) 'curr_property_cost' => string '62' (length=2) 'day_property' => string '19' (length=2) 'day_property_cost' => string '0' (length=1) 'curr_solar_generating' => string '2898' (length=4) 'curr_solar_export' => string '0' (length=1) 'day_solar_generated' => string '9' (length=1) 'day_solar_export' => string '0' (length=1) 'curr_chan1' => string '2189' (length=4) 'curr_chan2' => string '2898' (length=4) 'curr_chan3' => string '885' (length=3) 'day_chan1' => string '7' (length=1) 'day_chan2' => string '9' (length=1) 'day_chan3' => string '2' (length=1) 1 => array (size=15) 'timestamp' => string '01/02/2014 00:00' (length=16) 'curr_property' => string '5215' (length=4) 'curr_property_cost' => string '54' (length=2) 'day_property' => string '37' (length=2) 'day_property_cost' => string '0' (length=1) 'curr_solar_generating' => string '2141' (length=4) 'curr_solar_export' => string '0' (length=1) 'day_solar_generated' => string '16' (length=2) 'day_solar_export' => string '0' (length=1) 'curr_chan1' => string '2173' (length=4) 'curr_chan2' => string '2141' (length=4) 'curr_chan3' => string '901' (length=3) 'day_chan1' => string '14' (length=2) 'day_chan2' => string '16' (length=2) 'day_chan3' => string '5' (length=1) 2 => array (size=15) 'timestamp' => string '01/02/2014 00:00' (length=16) 'curr_property' => string '5215' (length=4) 'curr_property_cost' => string '54' (length=2) 'day_property' => string '54' (length=2) 'day_property_cost' => string '0' (length=1) 'curr_solar_generating' => string '2157' (length=4) 'curr_solar_export' => string '0' (length=1) 'day_solar_generated' => string '23' (length=2) 'day_solar_export' => string '0' (length=1) 'curr_chan1' => string '2157' (length=4) 'curr_chan2' => string '2157' (length=4) 'curr_chan3' => string '901' (length=3) 'day_chan1' => string '21' (length=2) 'day_chan2' => string '23' (length=2) 'day_chan3' => string '8' (length=1) 3 => array (size=15) 'timestamp' => string '01/02/2014 00:00' (length=16) 'curr_property' => string '5183' (length=4) 'curr_property_cost' => string '54' (length=2) 'day_property' => string '71' (length=2) 'day_property_cost' => string '0' (length=1) 'curr_solar_generating' => string '2125' (length=4) 'curr_solar_export' => string '0' (length=1) 'day_solar_generated' => string '31' (length=2) 'day_solar_export' => string '0' (length=1) 'curr_chan1' => string '2173' (length=4) 'curr_chan2' => string '2125' (length=4) 'curr_chan3' => string '885' (length=3) 'day_chan1' => string '28' (length=2) 'day_chan2' => string '31' (length=2) 'day_chan3' => string '11' (length=2)
$csvdat?