Multidimensional associative array delcaration

I would like to implement an associative array that stores an AXI transaction(type), indexed by an ID(integer) and has two dimensions, one for the address and one for data.

How do I declare this?

Later, I want to search this array by ID first and then get the corresponding address and data. Could you please share idea on how to do it?

Thanks.

In reply to UVM_learner6:

Syntax of Associative array declaration :
// Value Array_Name [ key ];
data_type array_identifier [ index_type ];



///Class which contain the addr and data of the AXI transaction
class axi_tran;
  logic [31:0] addr;
  logic [31:0] data;
  
  //other methods
endclass : axi_tran


module my_prg;
  
  //Associative array of axi_tran type and int key/index type 
  axi_tran axi_tran_arr[int];
  
  initial begin
    for (int id=0; id<5; id++)begin
      axi_tran a;
      a = new();
      a.addr = $urandom();
      a.data = $urandom();
      $display("AXI ID %d, AXI ADDR : %h, AXI DATA = %h", id, a.addr, a.data);
      
      //store the axi transaction in the associative array based on ID 
      axi_tran_arr[id] = a;
    end
    
    $display("*********** Checking  the ADDR , DATA of the AXI transaction for specific ID *********");
    
    $display("AXI ID %d, AXI ADDR : %h, AXI DATA = %h", 1, axi_tran_arr[1].addr, axi_tran_arr[1].data);

  end
  
endmodule : my_prg

In reply to Rahul Patel:

Thank you Rahul.

In reply to Rahulkumar Patel:

Hi Rahul,

One quick clarification - If I want to use another key to indicate 3 different masters, how do I change the declaration/storing of the associative array? I tried :

I declared it as axitransaction wr_input_array[int][int];

wr_input_array[0][int] = my_trans;

but it changed the depth of the array to be always 1 deep.

I want to be able to store/re-store based on the master number 0, 1, 2 and then for each master, by address.

In reply to UVM_learner6:

In reply to Rahulkumar Patel:
I want to be able to store/re-store based on the master number 0, 1, 2 and then for each master, by address.

No change require in following declaration. Memory will be automatically declared for 3rd master also when you store the transaction because it is declared as associative array.

axitransaction wr_input_array[int][int];

I would suggest you to go through the detail of associative array.