我有一個名爲$comments
的數組。如何按他們的類別列出評論? (操作數組)
當我var_dump($comments);
這裏是結果。
array
0 =>
object(stdClass)[11]
public 'comment_id' => string '1' (length=1)
public 'comment_article_id' => string '1' (length=1)
public 'comment_user_id' => string '2' (length=1)
public 'comment' => string 'Comment to article_id 1' (length=11)
public 'comment_date' => string '2016-03-10 20:06:43' (length=19)
1 =>
object(stdClass)[9]
public 'comment_id' => string '3' (length=1)
public 'comment_article_id' => string '1' (length=1)
public 'comment_user_id' => string '2' (length=1)
public 'comment' => string 'Another comment to article_id 1.' (length=14)
public 'c
' => string '2016-03-10 20:06:43' (length=19)
2 =>
object(stdClass)[6]
public 'comment_id' => string '5' (length=1)
public 'comment_article_id' => string '2' (length=1)
public 'comment_user_id' => string '2' (length=1)
public 'comment' => string 'Comment to article_id 2' (length=26)
public 'comment_date' => string '2016-03-10 20:06:43' (length=19)
這裏是我的功能,這給了我上面的結果:
public function ListComments($userid) {
$comments = $this->FindComments($userid);
var_dump($comments);
}
我想列出這樣的評論:
- 1(這是comment_article_id)
- 對article_id的評論1
-Another註釋ARTICLE_ID 1
-Comment到ARTICLE_ID 2
我不知道該怎麼manupulate我目前的陣列來獲得這樣的結果。
我想存檔這個沒有任何改變FindComments()
函數。
我必須盡我所能在這裏做ListComments()
函數。
可能我需要一個foreach循環,但我沒有申請。
你要解釋一些有關你的答案嗎? – HddnTHA
謝謝。但是我怎樣才能達到我想要的輸出?我做了'var_dump($ result);'但我沒有得到任何線索。 – IDontKnow