0

I am trying to create a mapping where the key is an ID and it is pointing to an array of dates. The idea is to enter a date everytime the ID comes to the facility so I can have an array of dates next to the ID I created a struct with a uint VDates and a mapping with a uint key and pointing to the struct but as an array

struct visitDates{
    uint VDates;
}
    mapping (uint => visitDates[]) public dates; 

This is the add date function where I set the key as secret number and push the date entry into the array

function AddVisitDate (uint _date, uint _SecretNum ) public {
           dates[_SecretNum].push(visitDates(_date));
       } 

The problem is in getVisitDate function where the idea is to pass the secret number and I call the mapping and I need it to return the array containing the dates of visit of that secret number i dont not know how to write this function so if u have any suggestion please suggest

1 Answer 1

0

The function would look like this, just use the secret number to get the mapped value:

    function getVisitDate (uint _SecretNum ) public view returns( visitDates[] memory){
           return dates[_SecretNum];
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.