Tuesday, 15 February 2011

PHP Multidimensional arrays keys and values -



PHP Multidimensional arrays keys and values -

i'm struggling head around multi-dimensional arrays in php, background c , java both of have no issues arrays!

i'm trying read sql database list of months, each month has list of values corresponding value.

ie.

2014-01-01, ("val1", "val2", "val3", "val4", "val5"), (3, 4, 7, 5, 3) 2014-02-01, ("val1", "val2", "val3", "val4", "val5"), (5, 3, 6, 2, 8) 2014-03-01, ("val1", "val2", "val3", "val4", "val5"), (6, 5, 4, 3, 2) ...

i can read values, can split them down, want able add together values array putting values right month.

i c/java i'd create array this;

[0,0,0,0,0,0,0,0,0,0,0,0] - val1 goes in here [0,0,0,0,0,0,0,0,0,0,0,0] - val2 goes in here [0,0,0,0,0,0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0,0,0,0,0] - val5 goes in here

then parse through values, i'd pick month, , add together values read right month.

i can create array in php, need know, there blindingly obvious way i've missed in coffee/sleep deprived state can like;

if want alter position 11 in the 2nd array 6 in c this;

array[2][11] = 6

is there equivalent in php?

this work:

$myarray[2][11] = 6; $myarray[2][12] = 7; var_dump( $myarray ); //view construction

php arrays multidimensional-array

No comments:

Post a Comment