IPB

Career Guidance | Technical Jobs | Walkin Interview & Job Fairs | Fresher Jobs

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Writing to and reading from dynamic arrays
Misha Singh
post Nov 20 2009, 04:49 AM
Post #1


Advanced Member
***

Group: Members
Posts: 8,266
Joined: 23-November 08
Member No.: 6,521



I'll preface this by saying that I'm more of a "big picture" developer. The finer nuances of syntax are not my specialty.

I'm looking to take an array, e.g.:


PHP Code:





$someArray = array(0, 9, 10, 11, 12, 23);








and create an integer inside of a different multi-dimensional array, whose value would, when hard-coded, be assigned using the following:


PHP Code:





$anotherArray[0][9][10][11][12][23] = 1;








For reference, when var_dump()'d, the above code outputs:


Code:
Array
(
[0] => Array
(
[9] => Array
(
[10] => Array
(
[11] => Array
(
[12] => Array
(
[23] => 1
)

)

)

)

)

)
Naturally, I would also like to be able to read from the array, with something like:


PHP Code:





$myInt = $anotherArray[0][9][10][11][12][23];









I have tried to create the array with (following from the above examples):


PHP Code:





$container = array();


for (
$j = 0; $j < count($someArray); $j++) {

$dimensions .= '[' . $someArray[$j] . ']';

}


$container[]{$dimensions} = 1;








The problem is that, when var_dump()'d, $container looks like this:


Code:
[0] => Array
(
[[0][9][10][11][12][23]] => 1
)
I need the nested structure, as demonstrated a few code-blocks up.

To be clear, the 0, 9, 10, etc. in the above examples are dynamic; there could be any number of dimensions to the array, and I need for this to work within a "for" loop.

Thanks for any help!
Go to the top of the page
 
+Quote Post

Fast ReplyReply to this topicStart new topic
Tags
No Tag inserted yet

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 12th March 2010 - 03:55 PM