I have a small php snippet that shows me the number of requests received, this is the code written:

$user_id = get_current_user_id();
$new_reqs = UM()->Friends_API()->api()->count_friend_requests_received( $user_id );
echo $new_reqs;

The snippet works perfectly and shows me the number of requests received. The problem is that if I have not received requests it shows nothing. How can I show 0 if I have not received requests? I've tried adding this code

    if (empty($new_reqs)) { echo "0"; }

but it doesn't work.

Thanks.

1 Answers

1
Jim Grant On Best Solutions

I would do the following code:

echo ($new_reqs > 0) ? $new_reqs : 0 ;

That way if requests have been received, it will work as before, else it will print 0.