Jump to content

get the key


clankill3r

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.