2013-02-04 29 views
0

我想指望所有的数组在一起,但不知道我的问题在json_encode和添加阵列尽数

$output = array(
    'facebook'=> isset($finfo[0]) ? $finfo[0]->total_count : NULL, 
    'twitter'=> isset($tinfo->count) ? $tinfo->count : NULL, 
    'delicious'=> isset($dinfo[0]) ? $dinfo[0]->total_posts : NULL, 
    'pinterest'=> isset($pinfo->count) ? $pinfo->count : NULL, 
    'googlePlus'=> isset($gplus[0]['result']) ? $gplus[0]['result']['metadata']['globalCounts']['count'] : NULL 

); 

function getSocialCount($output){ 
    return json_encode($output[facebook]) + json_encode($output[twitter]) + json_encode($output[pinterest]) + json_encode($output[googlePlus]); 
} 

<div>All: <?php echo getSocialCount(); ?></div> 

我写的语法错误?

回答

1

是的,你的函数需要一个参数,你不会给它任何。

变化:

<?php echo getSocialCount(); ?> 

到:

<?php echo getSocialCount($output); ?> 
+0

感谢JEROEN。 4只眼睛好于2只眼睛;) – user2036282

0

也许你应该添加您的阵列$output到您的功能..

<?php echo getSocialCount($output); ?>