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,740 points
1,099 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,370 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 4, 2019 in Blockchain by Omkar
• 69,220 points
857 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 aryya
• 7,460 points
732 views
+1 vote
1 answer

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

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,417 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
1,232 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
1,916 views
0 votes
1 answer

Converting 5e-08 to decimal in PHP

Use printf with the appropriate format specifier: printf("%.8f", 5 / ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
3,261 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,370 points
1,534 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP