clankill3r Posted November 9, 2011 Share Posted November 9, 2011 i have a array: Array ( [17] => 3 [18] => 3 [19] => 3 [28] => 3 [29] => 3 [30] => 3 [32] => 3 [33] => 3 [35] => 3 [36] => 3 [37] => 3 [38] => 3 [40] => 2 [41] => 2 [43] => 2 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 1 [6] => 1 [7] => 1 [8] => 1 [21] => 1 [22] => 1 [23] => 1 [24] => 1 [25] => 1 [26] => 1 [27] => 1 [31] => 1 [34] => 1 [49] => 1 ) now i want to save all keys in a array where the value is 3 (count($words)). $filteredVisitIds = array(); // only add the ones that are equal to the ammount of search words foreach($valueCountArray as $valueCount) { if($valueCount == count($words)) { // $filteredVisitIds[] = ...the key of $valueCount... } } Link to comment https://forums.phpfreaks.com/topic/250805-get-the-key/ Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 You can use foreach with the keys as well. foreach( $array as $key => $value ) { echo $key . ' => ' . $value . '<br>'; } Link to comment https://forums.phpfreaks.com/topic/250805-get-the-key/#findComment-1286825 Share on other sites More sharing options...
clankill3r Posted November 9, 2011 Author Share Posted November 9, 2011 Warning: Invalid argument supplied for foreach() // count the double entry's $valueCountArray = array_count_values($all_visitIds); //print_r2($valueCountArray); //echo(count($valueCountArray)); $filteredVisitIds = array(); // only add the ones that are equal to the ammount of search words foreach($valueCountArray as $valueCount) { if($valueCount == count($words)) { foreach($valueCount as $key => $value) { $filteredVisitIds[] = $key; } } } print_r2($filteredVisitIds); Link to comment https://forums.phpfreaks.com/topic/250805-get-the-key/#findComment-1286839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.