Answer the question
In order to leave comments, you need to log in
How to convert an associative array in PHP to a JSON array?
Hello. There is a task to generate a JSON keyboard object for a bot in VK. The structure is as follows:
{
"one_time": false,
"buttons": [
[{
"action": {
"type": "text",
"payload": "{\"button\": \"1\"}",
"label": "Negative"
},
"color": "negative"
},
{
"action": {
"type": "text",
"payload": "{\"button\": \"2\"}",
"label": "Positive"
},
"color": "positive"
},
{
"action": {
"type": "text",
"payload": "{\"button\": \"2\"}",
"label": "Primary"
},
"color": "primary"
},
{
"action": {
"type": "text",
"payload": "{\"button\": \"2\"}",
"label": "Secondary"
},
"color": "secondary"
}
]
]
}
$buttons = [
"action" => [
"type" => "location"
]
];
$keyboard = [
'one_time' => true,
'buttons' => $buttons
];
{"one_time":true,"buttons":{"action":{"type":"location"}}}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question