-1

我有一个这样的数组:

Array
(
    [played] => 2
    [random] => 0
    [win] => 2
    [draws] => 11
    [passes] => 2
    [swaps] => 6
    [hpoints] => 0
    [lpoints] => -12
    [hmoves] => 11
    [lmoves] => 0
    [hpasses] => 1
    [lpasses] => 0
    [hswaps] => 3
    [lswaps] => 0
    [today] => 2013-04-04
    [tdpoints_temp] => -24
    [tdpoints] => -24
    [htdpoints] => 0
    [ltdpoints] => -12
)

然后我将数组分成单独的值,如下所示:

foreach($userStats as $singleStat){
    $played = $singleStat['played'];
    $random = $singleStat['random'];
    $win = $singleStat['win'];
    $draws = $singleStat['draws'];
    $passes = $singleStat['passes'];
    $swaps = $singleStat['swaps'];
    $hpoints = $singleStat['hpoints'];
    $lpoints = $singleStat['lpoints'];
    $hmoves = $singleStat['hmoves'];
    $lmoves = $singleStat['lmoves'];
    $hpasses = $singleStat['hpasses'];
    $lpasses = $singleStat['lpasses'];
    $hswaps = $singleStat['hswaps'];
    $lswaps = $singleStat['lswaps'];
    $today = $singleStat['today'];
    $tdpoints_temp = $singleStat['tdpoints_temp']-$playeridPoints;
    $tdpoints = $singleStat['tdpoints']-$playeridPoints;
    $htdpoints = $singleStat['htdpoints'];
    $ltdpoints = $singleStat['ltdpoints'];
} 

除了没有问题。当我回显它们时,所有为“0”的变量($random、$hpoints、$lmoves、$lpasses、$lswaps 和 $htdpoints)都显示为“-”?我不知道为什么,我希望他们按应有的方式返回“0”。

任何帮助表示赞赏并提前感谢:-)

//########### 编辑 #############//

这是完整的代码:

if($cacheAvailable == true){ // WE GOT A CACHE
    //$memcache->delete('stats_'.$opponent);
    $userStats = $memcache->get('stats_'.$opponent);

    echo '<pre>';
    print_r($userStats);
    echo '</pre>';

    foreach($userStats as $singleStat){
        $played = $singleStat['played'];
        $random = $singleStat['random'];
        $win = $singleStat['win'];
        $draws = $singleStat['draws'];
        $passes = $singleStat['passes'];
        $swaps = $singleStat['swaps'];
        $hpoints = $singleStat['hpoints'];
        $lpoints = $singleStat['lpoints'];
        $hmoves = $singleStat['hmoves'];
        $lmoves = $singleStat['lmoves'];
        $hpasses = $singleStat['hpasses'];
        $lpasses = $singleStat['lpasses'];
        $hswaps = $singleStat['hswaps'];
        $lswaps = (int)$singleStat['lswaps']; 
        $today = $singleStat['today'];
        $tdpoints_temp = $singleStat['tdpoints_temp']-$playeridPoints;
        $tdpoints = $singleStat['tdpoints']-$playeridPoints;
        $htdpoints = $singleStat['htdpoints'];
        $ltdpoints = $singleStat['ltdpoints'];
    }
    echo 'This swap: '.$lswaps.'<br><br>';
}
4

1 回答 1

2

0 不能转换为'-' 一定是你做了一些转换

尝试使用类型转换

$played = (int)$singleStat['played'];
$random = (int)$singleStat['random'];
于 2013-04-04T12:40:52.477 回答