0

Hi all,

I have an array $pTimeseries with 365 items inside it. I use a simple for statement, as below:

//Add TimeStamp to Historic Data
for($i = 0; $i < (count($pTimeseries)); $i++) {
    $pTimeseries[$i][1] = $rawData[$i + $backdate][0];
}

In my Apache error logs I get "Undefined offset: 366" all the way up to 'Undefined offset: 327480' after which I get a memory error...

Why/how is the for statement not following the limit??

3
Contributors
5
Replies
25
Views
2 Years
Discussion Span
Last Post by James_43
0

For some bizzare reason, if I set $i < 1 as an example, suddenly the array goes from -5 to 360.... Can you even have negative array indexes?!

Edited by James_43

1

Hi, the undefined offset is probably given by:

$rawData[$i + $backdate]

Check if the index key exists:

$key = $i + $backdate;
if(array_key_exists($key, $rawData))
    $pTimeseries[$i][1] = $rawData[$key][0];

Edited by cereal

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.