Javascript:
function array_search( needle, haystack, strict ) { // Searches the array for a given value and returns the corresponding key if
// successful
//
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
var strict = !!strict;
for(var key in haystack){
if( (strict && haystack[key] === needle) || (!strict && haystack[key] == needle) ){
return key;
}
}
return false;
}
Примеры:
array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
'surname'
|
|
|
|