I have a PHP script, and in this script I have an associative array looks like this, so I have pairs of keys and values in the array:
$arr = array('First' => 'One', 'Second' => 'Two', 'Third' => 'Three');
I have a table in AWS DynamoDB, and on that table I have an attribute named details and its type is Map, which means it has a String Key and a String Value for every item in the Map, so eventually it looks like the associative array from the beginning of the question.
Now, what I want is to upload the associative array to the table at DynamoDB, to the details Map-type attribute.
On the DynamoDB PHP SDK Documentation, it is written that I need to upload the Map keys and values pairs manually, like this:
'M' => array(
// Associative array of custom 'AttributeName' key names
'AttributeName' => array(
// Associative array of custom key value pairs
),
// ... repeated
),
But, the problem is that I don't know how many pairs of keys and values are in the associative array, so I cannot split it to 2 arrays of keys and values and to upload it with the number of pairs I have:
$keys[0] => array('S' => $values[0]),
$keys[1] => array('S' => $values[1]),
...
Another option that I thought about was to create a loop, and each time to update the attribute in the DynamoDB table, but the problem is that it is a Map-type attribute, so I cannot use ADD or SET to update the map. I cannot also retrieve the exist map on the DB and add the new pair, because then I still stay with a Map-type variable.
I thought of another option, which is to split it to 2 arrays of keys and values and upload those arrays to the DB, but then I would lose the order of the strings in the arrays and the matching between the keys and the pairs, because DynamoDB orders the arrays alphabetically, so there is no match by the index number.
What can I do to upload the associative array to the DynamoDB table?