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??

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?!

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];

//ini_set('display_errors', 1);
//error_reporting(E_ALL & ~E_NOTICE);

foreach($key as $rawData)
    //$rawData[] = $item->toArray();
    echo $rawData;

Cereal was right, missed that mistake. Thanks!