2015-11-27 85 views
0
Array ([0] => LOWER CERVICAL) 
Array ([0] => LOWER CERVICAL [1] => Degenerative) 
Array ([0] => LOWER CERVICAL [1] => Degenerative [2] => Degenerative) 
Array ([0] => LOWER CERVICAL [1] => Degenerative [2] => Degenerative [3] => Cervical myelopathy(Spondylotic)) 

我使用數組來保存結果,但我不知道如何將上述數組格式轉換爲下面的字符串格式。我作爲預期輸出給將多維數組轉換爲字符串在PHP中

Expeceted輸出到上述陣列格式轉換爲字符串:

LOWER CERVICAL>>Degenerative>>Degenerative>>Cervical myelopathy(Spondylotic)>> 

代碼:

while($rsdiag=mysql_fetch_array($sqldiag)) 
{ 
    $items[$i] = $rsdiag['di_name']; 
    echo $rsdiag['di_name'].">>"; 
    print_r($items); 
    $i++; 
} 
+0

你什麼到目前爲止嘗試過?發佈您的嘗試 –

+0

這是1陣列還是打印在一個循環? – Rizier123

+1

'echo implode(「>>」,$ items)。 「>>」;' – Rizier123

回答

0

我要注意,這可能是不太好但這裏是一些解決方案,我可以建議只有當你沒有大數據量來進行:

rsort($array); 
$map = array(); 

// $array is your strings array 
foreach($array as $item) { 
    if(empty($map)){ 
    // First element catch the express.. 
    $map[] = $item; 
    continue; 
    } 
    $notFound = TRUE; 
    foreach($map as $mapItem){ 
    if(array_intersect_assoc($item, $mapItem) == $item){ 
     $notFound = FALSE; 
    } 
    } 
    if($notFound === TRUE) { 
    $map[] = $item; 
    } 
} 
foreach($map as $item){ 
    echo implode(" >> ",$item); 
}