In my PHP script, I get a POST reaction from an HTML form. One of the texts, is a list of things, separated by a comma (for example: "apple, banana, orange").
I want to upload this text, among with other texts which got POSTed to a table on Amazon DynamoDB, but I don't want to upload it as a string, but as a string set (for example: ["apple", "banana", "orange"]).
Now, I know how to split the string:
$list = "apple, banana, orange";
$fruits = explode(", ", $list);
echo $fruits[0]; // apple
echo $fruits[1]; // banana
echo $fruits[2]; // orange
And, I also know how to upload a string array to DynamoDB:
$sdk = new Aws\Sdk([
'region' => 'us-west-2',
'version' => 'latest'
]);
$dynamodb = $sdk->createDynamoDb();
$response = $dynamodb->putItem([
'TableName' => 'ProductCatalog',
'Item' => [
'Id' => ['N' => '104' ], // Primary Key
'Title' => ['S' => 'Book 104 Title' ],
'ISBN' => ['S' => '111-1111111111' ],
'Price' => ['N' => '25' ],
'Authors' => ['SS' => [$authorA, $authorB] ]
]
]);
But, how to upload the strings, if I don't know the exact number?
If I knew the number of items then it would be like:
'Fruits' => ['SS' => [$fruits[0], $fruits[1], $fruits[2]]
But the problem is that I don't know.
How can I upload the string array to DynamoDB although I don't know the exact number of strings in the array?
'Fruits' => ['SS' => $fruits]?