2016-10-02 45 views
0

为什么以下代码显示此错误?为什么下面的代码显示不支持的操作数类型错误?

Xdebug: Fatal error: Unsupported operand types in C:\wamp\www\wordpress\wp-content\themes\testtheme\single-football_league.php on line 63.

foreach (array_keys($team_points + $team_points2) as $key) { 
     $total_points_final[$key] = (isset($team_points[$key]) ? $team_points[$key] : 0) + (isset($team_points2[$key]) ? $team_points2[$key] : 0); 
    } 
+0

大概是因为这两个变量中的一个:'$ team_points','$ team_points2'不是一个数组。什么是输出:'var_dump($ team_points);'''var_dump($ team_points2);'? – Rizier123

+0

这是一个很好的代码示例,不应该使用三元运算符......非常难以阅读。 –

+0

null和 array(size = 1) ''=> int 34 。 – bdtheme

回答

0

你们是不是来连接$ team_points和$ team_points2?如果是这样,你应该使用array_merge:http://php.net/manual/en/function.array-merge.php

foreach (array_keys(array_merge($team_points, $team_points2)) as $key) { 
     $total_points_final[$key] = (isset($team_points[$key]) ? $team_points[$key] : 0) + (isset($team_points2[$key]) ? $team_points2[$key] : 0); 
    } 
相关问题