Function: array_key_exists version 20

Function:
Description: Checks if the given key or index exists in the array.
Version:
Status: latest
Date: 2011-12-20 04:34
Summary: Import from phpjs.
Programmer: jj5
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
function array_key_exists (key, search) {
    // http://jsphp.co/jsphp/fn/view/array_key_exists
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Felix Geisendoerfer (http://www.debuggable.com/felix)
    // *     example 1: array_key_exists('kevin', {'kevin': 'van Zonneveld'});
    // *     returns 1: true
    // input sanitation
    if (!search || (search.constructor !== Array && search.constructor !== Object)) {
        return false;
    }

    return key in search;
}
[top]

Comments

There are no comments yet, be the first!

Please Login or Register to post comments.