Arif Hossin Arif Hossin - 2 months ago 7
PHP Question

Why following codes shows Unsupported operand types error?

Why following codes shows this error?


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);
}

Answer

Are you trying to concatenate $team_points and $team_points2? If so, you should use 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);
    }