Answer the question
In order to leave comments, you need to log in
How to write a variable?
Execute the request
$friends_getRequests = curl( 'https://api.vk.com/method/friends.getRequests?offset=1&count=1&extended=1&need_viewed=1&access_token='.$token);
{"response":[{"uid":33224900},{"uid":205869219},{"uid":321678938},{"uid":364608800},{"uid":360153341},{"uid":361830009},{"uid":277374452},{"uid":232364661},{"uid":81323385},{"uid":345063168},{"uid":359946852},{"uid":348982141},{"uid":19482073},{"uid":217818751},{"uid":275193481}]}
Answer the question
In order to leave comments, you need to log in
$response = '{"response":[{"uid":33224900},{"uid":205869219},{"uid":321678938},{"uid":364608800},{"uid":360153341},{"uid":361830009},{"uid":277374452},{"uid":232364661},{"uid":81323385},{"uid":345063168},{"uid":359946852},{"uid":348982141},{"uid":19482073},{"uid":217818751},{"uid":275193481}]}';
$data = json_decode($response, true);
if (json_last_error() === JSON_ERROR_NONE && isset($data['response'][0]['uid'])) {
$user_1 = $data['response'][0]['uid'];
}
This is a string in JSON format, it must be parsed using json_decode, there are examples and lessons on the Internet.
Something like this:
$s = '{"response":[{"uid":33224900},{"uid":205869219},{"uid":321678938},{"uid":364608800},{"uid":360153341},{"uid":361830009},{"uid":277374452},{"uid":232364661},{"uid":81323385},{"uid":345063168},{"uid":359946852},{"uid":348982141},{"uid":19482073},{"uid":217818751},{"uid":275193481}]}';
$json = json_decode($s);
$user_1 = $json->{'response'}[0]->{'uid'};
echo($user_1);
I'll write a little more. First you need to check if the json is parsed correctly and no errors have occurred, and then iterate over each user and get an array of their id.
$s = '{"response":[{"uid":33224900},{"uid":205869219},{"uid":321678938},{"uid":364608800},{"uid":360153341},{"uid":361830009},{"uid":277374452},{"uid":232364661},{"uid":81323385},{"uid":345063168},{"uid":359946852},{"uid":348982141},{"uid":19482073},{"uid":217818751},{"uid":275193481}]}';
$json = json_decode($s);
$users = array();
if (!json_last_error())
{
foreach($json->response as $user)
{
$users[] = $user->uid;
}
}
var_dump($users);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question