2011-07-03 117 views
0

新手技術難點在這裏。 希望我能解釋清楚。我的數據庫中有 ,我有snFreq,snFreq2,snFreqIV,snFreqTube,snFreqTrach,snFreqCath,snFreqWound和snFreqOstomy。 我寫了一個isset來檢查每列是否存在數據,然後用預設文本創建一個變量。 在所有的檢查點之後,我想將它包含在一個短語中,但不想包含「0」數據。出於某種原因,我的輸出仍然顯示空白數據的多個逗號。 下面是一個輸出示例: SN頻率/持續時間:QD X 60天+ 2次IV併發症,管狀體併發症,,,< =有額外逗號的PRN訪問?在我的DB中: snFreq = QD X 60 DAYS,snFreq2 = 1,snFreqIV =PHP內爆陣列問題

if(isset($rowPlanOfCare['snFreq'])){$snFreq = "SN FREQUENCY/DURATION: " . $rowPlanOfCare['snFreq'];} 
    if(isset($rowPlanOfCare['snFreq2'])){$snFreq2 = " + 2 PRN VISITS FOR ";} 
    if(isset($rowPlanOfCare['snFreqIV'])){$snFreqIV = "IV COMPLICATIONS";} 
    if(isset($rowPlanOfCare['snFreqTube'])){$snFreqTube = "TUBE FEEDING COMPLICATIONS";} 
    if(isset($rowPlanOfCare['snFreqTrach'])){$snFreqTrach = "TRACHEOSTOMY CARE COMPLICATIONS";} 
    if(isset($rowPlanOfCare['snFreqCath'])){$snFreqCath = "CATHETER CARE COMPLICATIONS";} 
    if(isset($rowPlanOfCare['snFreqWound'])){$snFreqWound = "WOUND CARE COMPLICATIONS";} 
    if(isset($rowPlanOfCare['snFreqOstomy'])){$snFreqOstomy = "OSTOMY CARE COMPLICATIONS";} 
    $snFrequency = $snFreq . $snFreq2 . implode(", ",array($snFreqIV, $snFreqTube, $snFreqTrach, $snFreqCath, $snFreqWound, $snFreqOstomy)) . "\n \n "; 

最終輸出應僅顯示:SN頻率/ DURATION:FOR IV併發症,管飼併發症< == QD X第60天+ 2 PRN VISITS沒有其他逗號。

我希望你能幫我解決這個問題。提前致謝! :)

+0

isset是不一樣的空() – 2011-07-03 06:54:37

+0

'如果(isset($ rowPlanOfCare [ 'snFreqOstomy'])&& $ rowPlanOfCare [ 'snFreqOstomy'] =」「! )) – MLS

回答

0

試試這個:

$snFrequency = $snFreq . $snFreq2 . implode(", ",array_filter(array($snFreqIV, $snFreqTube, $snFreqTrach, $snFreqCath, $snFreqWound, $snFreqOstomy))) . "\n \n "; 
+0

工程就像一個魅力!非常感謝! –

+0

不客氣! – AlienWebguy