2017-02-06 23 views
-2
Array 
(
[0] => stdClass Object 
    (
     [features_id] => 2 
     [features_type] => TV 
    ) 

[1] => stdClass Object 
    (
     [features_id] => 5 
     [features_type] => New balls 
    ) 

[2] => stdClass Object 
    (
     [features_id] => 6 
     [features_type] => Basketball pitch 
    ) 
) 

對於我的陣列獲取的結果我想顯示這個紀錄由逗號等分離:如何逗號分隔的多個數組對象值的值顯示

New balls,Basketball pitch. 

通過使用foreach如何寫不知道如何得到這種類型的結果

+0

它的對象... $ val-> features_type –

+0

你能給例如BCZ我是新的張貼答.. –

+0

謝謝你,它的解決 –

回答

0

解決方法很簡單:

foreach($array as $item){ 
    echo $item->features_type.','; 
} 
+0

PHP –

3

您可以在不使用foreach循環的情況下實現輸出。請嘗試下面的代碼。

$singlArray = array_column($multiDimArray, 'features_type') // this convert multiple dimension array to single array 
$finalValue= implode(',',$singlArray); 
+0

偉大:) +1非常聰明的辦法 –

+0

很好的邏輯。 +1用於智能思考。 –

+0

@HarshBarach非常感謝 – sunilwananje