-1
我有一個這樣的數組:當數組中值爲0它變成 -
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'];
}
沒問題除。所有變量($ random,$ hpoints,$ lmoves,$ lpasses,$ lswaps和$ htdpoints)都是「0」,當我回應它們時,會顯示爲「 - 」我不知道爲什麼,我想讓他們按照他們的要求返回「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>';
}
必須有一些代碼是這樣做的。它不能自動完成。你能告訴我們你到底在哪裏迴應它嗎? – Rikesh 2013-04-04 12:35:59
我想這不是全部的foreach,你還在裏面做了什麼? – Shoe 2013-04-04 12:36:07
我認爲邪惡的代碼嚮導騙你... – andreapier 2013-04-04 12:37:42