Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c5156c

Browse files
committed
Update frequently-asked-questions.rst
1 parent 5dd8136 commit 0c5156c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/frequently-asked-questions.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,23 @@ Are mappings iterable?
172172
Mappings themselves are not iterable, but you can use a higher-level
173173
datastructure on top of it, for example the `iterable mapping <https://github.com/ethereum/dapp-bin/blob/master/library/iterable_mapping.sol>`_.
174174

175+
Can I put arrays inside of a mapping? How do I make a mapping of a mapping?
176+
===========================================================================
177+
178+
Mappings are already syntactically similar to arrays as they are, therefore it doesn't make much sense to store an array in them. Rather what you should do is create a mapping of a mapping.
179+
180+
An example of this would be::
181+
contract c {
182+
struct myStruct {
183+
uint someNumber;
184+
string someString;
185+
}
186+
mapping(uint => mapping(string => myStruct)) myDynamicMapping;
187+
function storeInMapping() {
188+
myDynamicMapping[1]["Foo"] = myStruct(2, "Bar");
189+
}
190+
}
191+
175192
Can you return an array or a string from a solidity function call?
176193
==================================================================
177194

0 commit comments

Comments
 (0)