2017-11-11 77 views
0

嘗試將我的數組值變爲可用變量。我想將這些值輸出爲可讀的內容,以便我可以在SELECT調用中使用它們以獲取我的下一個語句。最終結果我希望能夠做到像echo $ numresults這樣的東西,應該看起來像這樣9,8,6我的代碼如下所示將使用print_r,如下所示。將PHP數組轉換爲可用變量

Array ([0] => 9) Array ([0] => 8) Array ([0] => 6) 

我覺得我很接近但不知道如何將這個數組變成一個可用的變量。

while ($rowa = mysql_fetch_assoc($resulta)) { 
    if ($rowa['Count'] > 0) { 
     $cids[]= $rowa['id']; 
     display_id($rowa['id'], $levela + 1); 
    } elseif ($rowa['Count']==0) { 
     $cids[]= $rowa['id']; 
    } 

} 
print_r($cids); 
+0

讓我知道,如果你需要我的回答 –

+0

幫助使用RTRIM,SUBSTR當兩者都是非常接近但($字符串,0,-1); mb_substr($ string,0,-1);函數刪除最後一個,在輸出它將刪除所有的逗號,並把輸出從9,8,6,到986 –

回答

1
$cids = ""; 

while ($rowa = mysql_fetch_assoc($resulta)) { 
    if ($rowa['Count'] > 0) { 
     $cids = $cids . $rowa['id'] . ","; 
     display_id($rowa['id'], $levela + 1); 
    } elseif ($rowa['Count']==0) { 
     $cids = $rowa['id']; 
    } 
} 

print_r($cids); 
+0

但是,當使用rtrim,substr($ string,0,-1); mb_substr($ string,0,-1);函數刪除最後一個,在輸出時它將刪除所有的逗號,並將輸出從9,8,6到986, –

+0

修正它只是改爲$ cids。「,」。 $ ROWA [ 'ID'];來自$ cids。 $ rowa ['id']。 「」;現在工作很完美 –