我有一個多維數組。我想在所有數組中獲得特定值的計數。主數組中的這個數組取決於我添加了多少條評論。如何獲取數組中特定值的數量?
這裏是我的數組:
array(3) {
[0]=>
array(11) {
["comment_id"]=> string(1) "1"
["user_Id"]=> string(1) "2"
["comment"]=> string(18) "Commented! edited!"
["comment_datetime"]=> string(19) "2015-02-20 04:24:28"
["update_at"]=> string(19) "2015-02-20 04:23:18"
["user"]=> string(18) "Nishan Weerasinghe"
["delete"]=> string(1) "0"
["username"]=> string(6) "Nishan"
["picture_id"]=> NULL
["picture"]=> NULL
["picture_ext"]=> NULL
}
[1]=>
array(11) {
["comment_id"]=> string(2) "48"
["user_Id"]=> string(1) "2"
["comment"]=> string(4) "here"
["comment_datetime"]=> string(19) "2015-02-23 12:58:00"
["update_at"]=> string(0) ""
["user"]=> string(18) "Nishan Weerasinghe"
["delete"]=> string(1) "0"
["username"]=> string(6) "Nishan"
["picture_id"]=> NULL
["picture"]=> NULL
["picture_ext"]=> NULL
}
[2]=>
array(11) {
["comment_id"]=> string(2) "49"
["user_Id"]=> string(1) "2"
["comment"]=> string(3) "dfg"
["comment_datetime"]=> string(19) "2015-02-23 14:46:56"
["update_at"]=> string(0) ""
["user"]=> string(18) "Nishan Weerasinghe"
["delete"]=> string(1) "1"
["username"]=> string(6) "Nishan"
["picture_id"]=> NULL
["picture"]=> NULL
["picture_ext"]=> NULL
}
}
我想了解有多少["delete"]=> 0
(答案應該按照本恩是2)計數是有主陣列中。
哪裏是你的企圖? 'count + array_filter'或者好的foreach應該就足夠了 – Ghost 2015-02-24 03:31:15