C
C
Comex72016-08-25 10:57:46
PHP
Comex7, 2016-08-25 10:57:46

How to find out if a specific id has been liked or not?

Hello. I need to find out if I liked, for example, uid '1', on a photo.
Wrote this code:

$vkPhpSdk = new VkPhpSdk(); 

$result = $vkPhpSdk->api('likes.getList', array( 
'type' => 'photo', 
'owner_id' => '123456789', 
'item_id' => '987654321', 
'page_url' => '', 
'filter' => 'likes', 
'friends_only' => '0', 
'extended' => '1', 
'offset' => '1', 
'count' => '1000', 
'skip_own' => '0' 
));

for($i = 0; $i < $result['response']['count']; $i++) { 
if($result['response']['items'][$i]['uid'] == $user['uid']) { 
echo 'like!'; 
break; 
} else { 
echo 'No like!'; 
break; 
} 
}

I get the answer I need, but I don’t display the last liked user.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2016-08-25
@Sanasol

Why are you breaking the loop anyway?
You do not go beyond the first cycle.

D
Dmitry, 2016-08-26
@ExileeD

$result = 'no like';
for($i = 0; $i < $result['response']['count']; $i++) { 
if($result['response']['items'][$i]['uid'] == $user['uid']) { 
$result = 'Like';
break; 
}}
echo $result;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question