php - Count the number of times a value appears in a multi-dimensional array -


i have simple multi-dimensional array looks below. trying count how many times each value exists in array (i.e. arthritis => 3). have tried different count php functions returns number , not key => value pair. have looked on similar questions, nothing fits simplicity of array.

array(3) {       [0]=>       array(1) {         [0]=>         string(0) "arthritis"       }       [1]=>       array(4) {         [0]=>         string(7) "thyroid"         [1]=>         string(10) " arthritis"         [2]=>         string(11) " autoimmune"         [3]=>         string(7) " cancer"       }       [2]=>       array(6) {         [0]=>         string(7) "anxiety"         [1]=>         string(10) " arthritis"         [2]=>         string(11) " autoimmune"         [3]=>         string(15) " bone , joint"         [4]=>         string(7) " cancer"         [5]=>         string(8) " candida"       }       }  <?php print_r(count($items, count_recursive)); ?> 

one way flatten single dimension using array_merge() on sub-arrays, , count values using array_count_values():

$count = array_count_values(call_user_func_array('array_merge', $items)); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -