Index: array.c =================================================================== RCS file: /repository/php-src/ext/standard/array.c,v retrieving revision 1.255 diff -u -r1.255 array.c --- array.c 8 Jan 2004 08:17:30 -0000 1.255 +++ array.c 13 Jan 2004 21:10:20 -0000 @@ -1189,6 +1189,93 @@ } /* }}} */ +/* {{{ proto bool in_array_all(mixed needle1[, mixed needle2], mixed haystack [, bool strict]) + Checks if the given value exists in the array */ +PHP_FUNCTION(in_array_all) +{ + zval **array, /* array to check in */ + **entry, /* pointer to array entry */ + res; /* comparison result */ + zval ***args = NULL; + HashPosition pos_array; /* hash iterator */ + int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function; + int argc = ZEND_NUM_ARGS(); + int needle_num = argc-1, found_num = 0; + char *found; + + if (argc < 2) { + WRONG_PARAM_COUNT; + } else if (argc == 2) { + php_search_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + return; + } else { + /* Allocate arguments array and get the arguments, checking for errors. */ + args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0); + if (zend_get_parameters_array_ex(argc, args) == FAILURE) { + efree(args); + WRONG_PARAM_COUNT; + } + if (argc == 3 && Z_TYPE_PP(args[argc - 1]) != IS_ARRAY) { + efree(args); + php_search_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + return; + } + } + + if (Z_TYPE_PP(args[argc - 1]) != IS_ARRAY) { + if (Z_TYPE_PP(args[argc - 2]) != IS_ARRAY) { + efree(args); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong datatype for haystack"); + RETURN_FALSE; + } + convert_to_boolean_ex(args[argc - 1]); + if (Z_LVAL_PP(args[argc -1])) { + is_equal_func = is_identical_function; + } + needle_num--; + } + array = args[needle_num]; + + { + int ok = 1, i = 0; + for (i = 0; i < needle_num; i++) { + if (Z_TYPE_PP(args[i]) == IS_OBJECT) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong datatype for needle %d argument", i); + ok = 0; + } + } + if (!ok) { + efree(args); + RETURN_FALSE; + } + } + RETVAL_FALSE; + + found = (char *) ecalloc(needle_num, sizeof(char *)); + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(array), &pos_array); + while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(array), (void **)&entry, &pos_array) == SUCCESS) { + int j = 0; + for (;j < needle_num; j++) { + if (found[j]) { + continue; + } + is_equal_func(&res, *(args[j]), *entry TSRMLS_CC); + if (Z_LVAL(res)) { + found[j] = 1; + found_num++; + } + } + if (found_num == needle_num) { + RETVAL_TRUE; + } + zend_hash_move_forward_ex(Z_ARRVAL_PP(array), &pos_array); + } + efree(found); + efree(args); +} +/* }}} */ + + /* {{{ proto mixed array_search(mixed needle, array haystack [, bool strict]) Searches the array for a given value and returns the corresponding key if successful */ PHP_FUNCTION(array_search) Index: basic_functions.c =================================================================== RCS file: /repository/php-src/ext/standard/basic_functions.c,v retrieving revision 1.652 diff -u -r1.652 basic_functions.c --- basic_functions.c 8 Jan 2004 08:17:30 -0000 1.652 +++ basic_functions.c 13 Jan 2004 21:10:26 -0000 @@ -752,6 +752,7 @@ PHP_FE(min, NULL) PHP_FE(max, NULL) PHP_FE(in_array, NULL) + PHP_FE(in_array_all, NULL) PHP_FE(array_search, NULL) PHP_FE(extract, NULL) PHP_FE(compact, NULL) Index: php_array.h =================================================================== RCS file: /repository/php-src/ext/standard/php_array.h,v retrieving revision 1.46 diff -u -r1.46 php_array.h --- php_array.h 8 Jan 2004 17:32:51 -0000 1.46 +++ php_array.h 13 Jan 2004 21:10:27 -0000 @@ -50,6 +50,7 @@ PHP_FUNCTION(min); PHP_FUNCTION(max); PHP_FUNCTION(in_array); +PHP_FUNCTION(in_array_all); PHP_FUNCTION(array_search); PHP_FUNCTION(extract); PHP_FUNCTION(compact);