Reputation: 1
I am sending request using curl. this is json data :
{
"users": [
{
"userId": "123",
"userLink" : "www.example .com",
"userType": "au"
}
]
}
I am trying this but i need same above json:
$post = array(
"users" => array(
"userId" => "123",
"userLink" => "link",
"userType" => "au"
)
);
$out = array_values($post);
$post = json_encode($out);
print_r($post);
Upvotes: 0
Views: 27
Reputation: 78994
You need an additional array dimension, and if you use brackets [ ]
you can easily see how they look the same:
$post = [
"users" => [
[
"userId" => "123",
"userLink" => "link",
"userType" => "au"
]
]
];
$post = json_encode($post);
Also, don't use array_values
; that will remove the string key users
.
Upvotes: 2