将简单的php函数转换为变量

时间:2021-05-23 10:04:49

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...

我有一个简单的函数,我试图将其变成一个查询。想法是抓住facebook喜欢的数量(我已经做过),并将其传递给一个简单的等式(已经准备好),以计算出目标数量的喜欢百分比。我知道控制百分比的php现在将返回0.0 - 现在好了:)我只是无法弄清楚如何从函数到变量...

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 个解决方案

#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(); ?>

#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(); ?>