From: Andrei Zmievski Date: Thu, 1 Jun 2000 13:52:08 +0000 (+0000) Subject: @- Added third argument to in_array(). If it's true, then in_array() X-Git-Tag: PRE_EIGHT_BYTE_ALLOC_PATCH~156 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c818aec338a7353276a71459dcdc1da33e46503;p=php @- Added third argument to in_array(). If it's true, then in_array() @ will use strict comparison instead of the default one. (Andrei) Fixes bug #4753 --- diff --git a/TODO b/TODO index 8e0b8b806f..32c7d5d46f 100644 --- a/TODO +++ b/TODO @@ -10,7 +10,7 @@ Zend global ------ * sort ini entries so that phpinfo() show them in some nice order. - * make everything on the language-level independent of your locate setings. + * make everything on the language-level independent of your locale setings. * allow methods to be called as callbacks. eg: array_walk($myarray,"this->print()"); * always build the standalone executable as well as the chosen SAPI target. diff --git a/ext/standard/array.c b/ext/standard/array.c index fa1c210f83..33ba63e50e 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1027,18 +1027,20 @@ PHP_FUNCTION(array_walk) { } /* }}} */ -/* {{{ proto bool in_array(mixed needle, array haystack) +/* {{{ proto bool in_array(mixed needle, array haystack [, bool strict]) Checks if the given value exists in the array */ PHP_FUNCTION(in_array) { zval **value, /* value to check for */ **array, /* array to check in */ - **entry_ptr, /* pointer to array entry */ - *entry, /* actual array entry */ + **strict, /* strict comparison or not */ + **entry, /* pointer to array entry */ res; /* comparison result */ HashTable *target_hash; /* array hashtable */ + int (*compare_func)(zval *, zval *, zval *) = is_equal_function; - if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &value, &array) == FAILURE) { + if (ARG_COUNT(ht) < 2 || ARG_COUNT(ht) > 3 || + zend_get_parameters_ex(ARG_COUNT(ht), &value, &array, &strict) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1052,12 +1054,17 @@ PHP_FUNCTION(in_array) RETURN_FALSE; } + if (ARG_COUNT(ht) == 3) { + convert_to_boolean_ex(strict); + if (Z_LVAL_PP(strict) == 1) + compare_func = is_identical_function; + } + target_hash = HASH_OF(*array); zend_hash_internal_pointer_reset(target_hash); - while(zend_hash_get_current_data(target_hash, (void **)&entry_ptr) == SUCCESS) { - entry = *entry_ptr; - is_equal_function(&res, *value, entry); - if (zval_is_true(&res)) { + while(zend_hash_get_current_data(target_hash, (void **)&entry) == SUCCESS) { + compare_func(&res, *value, *entry); + if (Z_LVAL(res) == 1) { RETURN_TRUE; }