1

I have the following code to place an item in a table in dynamoDb it works fine. I want to nest an array in an array. For example, for the attribute 'color1' I want to make "A" to be array of items. How can I do that

$result = $client->putItem(array(
            'TableName' => 'usr',
            'Item' => array(
            'email'      => array('S'=>$_POST['email']),
            'first'    => array('S'=>$_POST['firstname']),
            'country'    => array('S'=>$_POST['country']),
            'last'   => array('S'=>$_POST['lastname']),
            'password' => array('S'=>$hashedpassword),
            'list'=> array('SS'=> array("1", "2", "3")),
            'color1'=> array('SS'=> array("A", "2", "5")),
            'phonenumber' =>array('S'=>$_POST['phonenumber']))

        ));

1 Answer 1

1

The exact same way you're doing it for the outer SS array; with mapping:

$result = $client->putItem(array(
    'TableName' => 'usr',
    'Item' => array(
        'email' => array('S' => $_POST['email']),
        'first' => array('S' => $_POST['firstname']),
        'country' => array('S' => $_POST['country']),
        'last' => array('S' => $_POST['lastname']),
        'password' => array('S' => $hashedpassword),
        'list' => array('SS '=> array("1", "2", "3")),
        'color1' => array('SS' => array("A" => array('1', '2'), "2", "5")),
        'phonenumber' => array('S' => $_POST['phonenumber'])
    )
));
Sign up to request clarification or add additional context in comments.

2 Comments

It works absolutely fine, as you can see here (where I've substituted $hashedpassword and your $_POST variables for 'a'). The problem is either in your $_POST (you should really check that each value is set), your $hashedpassword, or the function you are calling on $client.
interesting. I tried it with dynamodb and there is an error. I will look into it further thanks anyway

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.