2015-08-30 86 views
-3

大家好值我的代碼,結果是返回結果:無法在陣列

array (size=1) 
7 => string '0' (length=1) 

我不知道爲什麼我剛纔在$ DIST最後一個數組返回值?我需要$ dist的所有價值的結果,所以有人能幫助我嗎?

$dist  = array('1'=>'0','2'=>'1','3'=>'2','4'=>'3','5'=>'4','6'=>'5','7'=>'6'); 
foreach($dist as $key => $value) 
{ 
    $day  = time() - (24 * 60 * 60 * $value); 
    $pastday = time() - (24 * 60 * 60 * $value + 1); 
    $sql = "SELECT COUNT(id) as '" . $key . "' FROM profile_fields_plusmw3 WHERE banstart >= '" . $pastday . "' and banstart <= '" . $day . "' and pf_can_play_expire >= '".time()."'"; 
    $dayres = $db->sql_query($sql); 
    $row = $db->sql_fetchrow($dayres); 
} 
var_dump($row); 

回答

1

因爲你在每個循環中覆蓋你的變量。如果要獲得所有結果,必須將結果放回結果數組中。

$dist = array('1'=>'0','2'=>'1','3'=>'2','4'=>'3','5'=>'4','6'=>'5','7'=>'6'); 
$rows = array(); 
foreach($dist as $key => $value) { 
    // ... 
    $rows[] = $db->sql_fetchrow($dayres); 
} 
var_dump($rows);