Voting

: min(five, seven)?
(Example: nine)

The Note You're Voting On

neil at 11 out of 10
16 years ago
<?php

/*
* This function will return the keys of elements in the
* haystack where the value is found in array needle
*/

function array_value_intersect_keys( $array_haystack, $array_needle ){
$intersected = array_intersect( $array_haystack, $array_needle );
return
array_keys( $intersected );
}

// usage

$array_haystack = array( 1 => 2, 2 => 5, 'red' => 8, 9 => 14 );

$array_needle = array( 2, 8 );

$array_keys_of_intersecting_values = array_value_intersect_keys( $array_haystack, $array_needle );

print_r( $array_keys_of_intersecting_values );
?>

returns
Array
(
[0] => 1
[1] => red
)

<< Back to user notes page

To Top