I have an array which looks like this:
array(10) {
[0]=>
string(10) "2012-11-03"
[1]=>
string(1) "1"
[2]=>
string(10) "2012-11-04"
[3]=>
string(1) "3"
[4]=>
string(10) "2012-11-05"
[5]=>
string(1) "2"
[6]=>
string(10) "2012-11-06"
[7]=>
string(1) "7"
[8]=>
string(10) "2012-11-07"
[9]=>
string(1) "4"
}
I would like to get a new multidimensional array from this which would have 5 elements, where each element would look like this: $date => $number.
array(5) {
[0]=> array(2012-11-03 => 1)
[1]=> array(2012-11-04 => 3)
[2]=> array(2012-11-05 => 2)
[3]=> array(2012-11-06 => 7)
[4]=> array(2012-11-07 => 4)
}
I would like to use the dates as keys to te values that come after them. (I would eventually like to plot these values on a line chart, where x axis has the date and y has the value)
What kind of a (foreach?) loop can I write to do this?
I am getting this array from the following lines of code:
$data = "$start_date\n$value\n";
file_put_contents($id . '.csv', $data, FILE_APPEND);
$data = file_get_contents($id . '.csv');
$data_array = explode("\n", trim($data, "\n"));
var_dump($data_array); exit;