PHP-Funktionen in JavaScript
17. Oktober 2008 in Javascript
“Einfach genial!”, war mein erster Gedanke als ich den Blog von Kevin van Zonneveld durchstöberte, als ich auf der Suche nach einer Äquivalenten Javascript Funktion für PHP´s in_array war. Wer daher schon immer eine PHP Funktion in Javascript vermisst hat, wird diese auf Kevin´s Blog sicher finden. Mittlerweile befinden sich auf der Seite über 180 Javascript Funktionen.
Und hier der Javascript Code der in_array Funktion, den ich gesuchte habe:
function in_array(needle, haystack, strict) {
// http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// * example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
// * returns 1: true
var found = false, key, strict = !!strict;
for (key in haystack) {
if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
found = true;
break;
}
}
return found;
}
Zur Sammlung gehören:
abs, acosh, acos, addslashes, array, array_change_key_case, array_chunk, array_combine, array_count_values, array_diff, array_diff_assoc, array_diff_key, array_fill, array_flip, array_keys, array_key_exists, array_map, array_pad, array_pop, array_product, array_push, array_rand, array_reduce, array_reverse, array_search, array_shift, array_sum, array_unique, array_unshift, array_values, array_walk, array_walk_recursive, asinh, asin, atanh, atan, base64_decode, base64_encode, basename, base_convert, bin2hex, bindec, call_user_func_array, ceil, checkdate, chr, compact, cosh, cos, count, count_chars, crc32, create_function, date, decbin, dechex, decoct, defined, deg2rad, dirname, echo, empty, end, explode, exp, file, file_get_contents, floatval, floor, fmod, function_exists, getrandmax, get_class, get_included_files, hexdec, htmlentities, htmlspecialchars, htmlspecialchars_decode, html_entity_decode, http_build_query, hypot, implode, include, include_once, intval, in_array, ip2long, isset, is_array, is_bool, is_finite, is_infinite, is_int, is_nan, is_null, is_numeric, is_object, is_string, join, krsort, ksort, lcg_value, levenshtein, log, long2ip, ltrim, max, md5, md5_file, min, mktime, mt_getrandmax, mt_rand, nl2br, number_format, octdec, ord, parse_str, pi, pow, preg_quote, printf, print_r, rad2deg, rand, range, require, require_once, reset, round, rsort, rtrim, serialize, setcookie, sha1, sha1_file, shuffle, sinh, sin, sizeof, sleep, sort, soundex, split, sprintf, sqrt, strcasecmp, strchr, strcmp, stripos, stripslashes, strip_tags, stristr, strlen, strnatcmp, strncasecmp, strpbrk, strpos, strrev, strripos, strrpos, strstr, strtolower, strtoupper, str_ireplace, str_pad, str_repeat, str_replace, str_rot13, str_split, substr, substr_count, tanh, tan, time, trim, ucfirst, ucwords, unserialize, urldecode, urlencode, utf8_decode, utf8_encode, var_export, wordwrap

