pragma solidity ^0.4.18; contract MyContract { struct Cat { uint id; uint age; uint point; } Cat[] cats; function getCat(uint _id) public view returns(uint[]){ uint[] memory retCat = new uint[](3); if(cats.length <= _id){ return retCat; } Cat memory cat = cats[_id]; retCat[0] = cat.id; retCat[1] = cat.age; retCat[2] = cat.point; return retCat; } function getCatAll() public view returns(uint[]){ uint len = cats.length; uint[] memory data = new uint[](3*len); uint dataIdx = 0; for(uint i=0; i<len; i++){ Cat memory cat = cats[i]; data[dataIdx++] = cat.id; data[dataIdx++] = cat.age; data[dataIdx++] = cat.point; } return data; } function generateCat() public returns (uint[]){ Cat memory cat; cat.id = cats.length; cat.age = cat.id + 1000; cat.point = cat.id + 100000; cats.push(cat); // for return uint[] memory catData = new uint[](3); catData[0] = cat.id; catData[1] = cat.age; catData[2] = cat.point; return catData; } }
0.4.18