I've been running this code on remix ide on injected web3 with my ganache server in on state, then also i'm getting this error of invalid opcode. The code runs perfectly in rinkeby test network.
pragma solidity ^0.5.7;
contract cust{
struct a{
uint id;
string name;
}
a[] arr;
function set(uint x, string memory y ) public
{
a memory temp;
temp.id=x;
temp.name=y;
arr.push(temp);
}
function get(uint x) public view returns(uint,string memory){
uint i;
for(i=0;i<arr.length;i=i+1)
{
if(arr[i].id==x)
{
return(arr[i].id,arr[i].name);
}
}
}
}
a[] arr
tomapping (uint => string) arr
. Then you won't need thatfor
loop.