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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -