2

I have a simple function, which I'm trying to turn turn into a query. The idea is to grab the number of facebook likes (which I've done), and pass it into a simple equation (which is ready) to work out the percentage of likes against a target number. I know that the php controling the percentage will return 0.0 at the moment - that's fine for now :) I just can't work out how to get from the function to a variable...

Code as follows:

<?php 
function bfan() {
$pageID = 'VisitTywyn';
$info = json_decode(file_get_contents('http://graph.facebook.com/' . $pageID));
echo $info->likes;
} ?>

<?php bfan(); ?>

<?php
echo number_format(($num_amount/$num_total)*100, 1);
?>

Thanks for your help!

1 Answer 1

4

What you want to do is return your result so it can be passed to a variable.

<?php 
function bfan() {
$pageID = 'VisitTywyn';
$info = json_decode(file_get_contents('http://graph.facebook.com/' . $pageID));
return $info->likes;
} ?>

<?php $something = bfan(); ?>
Sign up to request clarification or add additional context in comments.

1 Comment

haha well you can still accept the answer by clicking the checkmark and soon you will be able to vote up with a little more rep.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.