开发者

PHP implode array issues

Newbie technical difficulty here. Hope I can explain this clearly. in My DB, I have snFreq, snFreq2, snFreqIV, snFreqTube, snFreqTrach, snFreqCath, snFreqWound, and snFreqOstomy. I wrote an isset to check each column if data exist, then make a variable with preset text. After all the checkpoints, I wanted to include this in a phrase, but don't want to include the "0" data. For some reason my output is still showing multiple commas with blank data. Here's an example output: SN FREQUENCY/DURATION: QD X 60 DAYS + 2 PRN VISITS FOR IV COMPLICATIONS, TUBE FEEDING COMPLICATIONS, , , , < = with extra commas? In my DB: snFreq = QD X 60 DAYS, snFreq2 = 1, snFreqIV = 1, and snFreqTube = 1, the rest are Null.

    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 ";

Final Output should only show: SN FREQUENCY/DURATION: QD X 60 DAYS + 2 PRN VISITS开发者_JS百科 FOR IV COMPLICATIONS, TUBE FEEDING COMPLICATIONS < == without the other commas.

I hope you can help me out with this issues. Thanks in advance! :)


Try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜