[PHP4BETA] CVS update: php4/ext/standard
| From: | andrey | Date: | Mon, 10 May 1999 21:10:50 +0000 |
| Subject: | [PHP4BETA] CVS update: php4/ext/standard | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-744@lists.php.net to get a copy of this message | ||
Date: Monday May 10, 1999 @ 17:10
Author: andrey
Update of /repository/php4/ext/standard
In directory php:/tmp/cvs-serv5352/ext/standard
Modified Files:
basic_functions.c basic_functions.h
Log Message:
Added in_array() function.
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.16 php4/ext/standard/basic_functions.c:1.17
--- php4/ext/standard/basic_functions.c:1.16 Sun May 9 14:40:59 1999
+++ php4/ext/standard/basic_functions.c Mon May 10 17:10:48 1999
@@ -294,6 +294,7 @@
{"setcookie", php3_SetCookie, NULL},
{"header", php3_Header, NULL},
PHP_FE(function_exists, NULL)
+ PHP_FE(in_array, NULL)
PHP_FE(extract, NULL)
{NULL, NULL, NULL}
@@ -2182,6 +2183,50 @@
}
}
+/* }}} */
+
+
+/* {{{ proto bool in_array(array haystack, mixed needle)
+ 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 */
+ res; /* comparison result */
+ HashTable *target_hash; /* array hashtable */
+
+ if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &value, &array) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ if (value->type == IS_ARRAY || value->type == IS_OBJECT) {
+ zend_error(E_WARNING, "Wrong datatype for first argument in call to in_array()");
+ return;
+ }
+
+ if (array->type != IS_ARRAY) {
+ zend_error(E_WARNING, "Wrong datatype for second argument in call to in_array()");
+ return;
+ }
+
+ 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;
+ if (entry->type == IS_STRING && entry->value.str.val == undefined_variable_string)
+ continue;
+ is_equal_function(&res, value, entry);
+ if (zval_is_true(&res)) {
+ RETURN_TRUE;
+ }
+
+ zend_hash_move_forward(target_hash);
+ }
+
+ RETURN_FALSE;
+}
/* }}} */
Index: php4/ext/standard/basic_functions.h
diff -u php4/ext/standard/basic_functions.h:1.3 php4/ext/standard/basic_functions.h:1.4
--- php4/ext/standard/basic_functions.h:1.3 Sat May 8 17:18:06 1999
+++ php4/ext/standard/basic_functions.h Mon May 10 17:10:48 1999
@@ -29,7 +29,7 @@
*/
-/* $Id: basic_functions.h,v 1.3 1999/05/08 21:18:06 andrey Exp $ */
+/* $Id: basic_functions.h,v 1.4 1999/05/10 21:10:48 andrey Exp $ */
#ifndef _BASIC_FUNCTIONS_H
#define _BASIC_FUNCTIONS_H
@@ -119,6 +119,7 @@
PHP_FUNCTION(defined);
PHP_FUNCTION(function_exists);
+PHP_FUNCTION(in_array);
PHP_FUNCTION(extract);
#if HAVE_PUTENV
--
PHP 4 Beta