Does Ethereum Solidity support Associative Arrays?

0 votes

For example - Arrays with named indexes or hashes. Something like PHP code;

$array = array(
"foo" => "some foo value",
"bar" => "some bar value",);
Sep 14, 2018 in Blockchain by digger
• 26,550 points
55 views

2 answers to this question.

0 votes

Solidity supports a type called mapping:

contract MappingExample {
    mapping(address => uint) public balances;

    function update(uint newBalance) {
        balances[msg.sender] = newBalance;
    }
}

http://solidity.readthedocs.io/en/develop/types.html#mappings

answered Sep 14, 2018 by slayer
• 29,170 points
0 votes

Here's a little example that passes values around observing fixed-size rules compatible with the ABI.

contract StructExample {

    struct MyStruct {
        bool isMyStruct;
        uint amount;
        address[3] addressList;
        bytes32 name;
    }

    // storage instance of MyStruct
    MyStruct myStruct;

    function StructExample(
        uint amount, 
        address address1, 
        address address2, 
        address address3,
        bytes32 name) 
    {
        myStruct.isMyStruct = true;
        myStruct.amount = amount;
        myStruct.addressList = [address1, address2, address3];
        myStruct.name = name;
    }

    function getMyStruct() 
      constant
      returns(
          bool isMyStruct,
          uint amount,
          address[3] addressList,
          bytes32 name)
    {
        return (
            myStruct.isMyStruct, 
            myStruct.amount, 
            myStruct.addressList, 
            myStruct.name);
    }
}

answered Sep 17, 2018 by Bobin

Related Questions In Blockchain

0 votes
1 answer

Does Hyperledger support Smart Contract like Ethereum?

Yes, but not exactly true. Ethereum uses ...READ MORE

answered Feb 3 in Blockchain by Omkar
• 67,660 points
51 views
0 votes
1 answer
0 votes
1 answer

Is it possible to claim Bitcoin Cash from an exchange that does not support it?

You can't claim BCH without knowing private ...READ MORE

answered Jul 17, 2018 in Blockchain by ariaholic
• 7,340 points
46 views
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,340 points
89 views
0 votes
2 answers

PHP: json_decode - reading category names

<?php function findHighestBid() { $result = ...READ MORE

answered Sep 7, 2018 in Blockchain by Shotgun
61 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
169 views
0 votes
1 answer

How to monitor Ethereum private network?

geth should be started with --metrics. try the ...READ MORE

answered Jul 11, 2018 in Blockchain by slayer
• 29,170 points
161 views