I have been working with a multi-dimensional array in my latest efs study and have hit a roadblock.
After reading Jay's example at this link I got brave and tried it.
Everything works OK until I need to expand the array beyond the limits I originally set up for the array. Since I don't know how many elements I'm going to need I can only think to set up an extremely large array, but it seems to me that there must be a better way.
Using Jay's example of a two-dimensional with 4 rows (see below), how would you add a 5th row to the array after it has already been defined?
Dale Sullivan
Multidimensional array test;
Row 0:[0,0][0,1][0,2][0,3];
Row 1:[1,0][1,1][1,2][1,3];
Row 2:[2,0][2,1][2,2][2,3];
Row 3:[3,0][3,1][3,2][3,3];
After reading Jay's example at this link I got brave and tried it.
Everything works OK until I need to expand the array beyond the limits I originally set up for the array. Since I don't know how many elements I'm going to need I can only think to set up an extremely large array, but it seems to me that there must be a better way.
Using Jay's example of a two-dimensional with 4 rows (see below), how would you add a 5th row to the array after it has already been defined?
Dale Sullivan
PHP Code:
myVar="Multidimensional array test; "
a = new Array(4)
for (i=0; i < 4; i++) {
a[i] = new Array(4)
for (j=0; j < 4; j++) {
a[i][j] = "["+i+","+j+"]"
}
}
for (i=0; i < 4; i++) {
str = "Row "+i+":"
for (j=0; j < 4; j++) {
str += a[i][j]
}
myVar += str +"; "
}
Multidimensional array test;
Row 0:[0,0][0,1][0,2][0,3];
Row 1:[1,0][1,1][1,2][1,3];
Row 2:[2,0][2,1][2,2][2,3];
Row 3:[3,0][3,1][3,2][3,3];
Comment