php - array count base on how many it appear -
i newbie in php.
i have mysqli_fetch_array looks inside while loop"
array(7) { ["id"]=> string(32) "00000000000000000000000000000001" ["name"]=> string(5) "admin" ["product"]=> string(32) "ps4" } array(7) { ["id"]=> string(32) "00000000000000000000000000000001" ["name"]=> string(5) "mike" ["product"]=> string(32) "iphone" } array(7) { ["id"]=> string(32) "00000000000000000000000000000001" ["name"]=> string(5) "mike" ["product"]=> string(32) "imac" } array(7) { ["id"]=> string(32) "00000000000000000000000000000001" ["name"]=> string(5) "mike" ["product"]=> string(32) "lcd monitor" }
i want count how many times admin , mike appear in loop: far know how loop:
while($row = mysqli_fetch_assoc($result)) { //i don't know next here: }
$count = array(); while( $row = mysqli_fetch_assoc($result) ) { $count[$row['name']] = isset( $count[$row['name']] ) ? $count[$row['name']] + 1 : 1; } var_dump($count);
Comments
Post a Comment