cvs: /php4 ChangeLog /php4/ext/standard basic_functions.c
| From: | Andrey Zmievski | Date: | Tue, 07 Sep 1999 18:30:00 +0000 |
| Subject: | cvs: /php4 ChangeLog /php4/ext/standard basic_functions.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-4207@lists.php.net to get a copy of this message | ||
andrey Tue Sep 7 14:30:00 1999 EDT
Modified files:
/php4 ChangeLog
/php4/ext/standard basic_functions.c
Log:
Added second parameter to array_keys() which allows returning keys
only for a specific value in an array.
Index: php4/ChangeLog
diff -u php4/ChangeLog:1.87 php4/ChangeLog:1.88
--- php4/ChangeLog:1.87 Mon Sep 6 15:24:47 1999
+++ php4/ChangeLog Tue Sep 7 14:29:58 1999
@@ -2,6 +2,8 @@
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ?? 1999, Version 4.0 Beta 3
+- Added second parameter to array_keys which specifies search value
+ for which the key should be returned (Andrey)
- Resourcified Informix driver (Danny)
- New resource handling for odbc, renamed to php_odbc.[ch]
- Make set_time_limit() work on Unix (Rasmus)
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.80 php4/ext/standard/basic_functions.c:1.81
--- php4/ext/standard/basic_functions.c:1.80 Mon Sep 6 16:13:23 1999
+++ php4/ext/standard/basic_functions.c Tue Sep 7 14:29:59 1999
@@ -3146,45 +3146,59 @@
PHP_FUNCTION(array_keys)
{
zval *input, /* Input array */
+ *search_value, /* Value to search for */
**entry, /* An entry in the input array */
+ res, /* Result of comparison */
*new_val; /* New value */
+ int add_key; /* Flag to indicate whether a key should be added */
char *string_key; /* String key */
ulong num_key; /* Numeric key */
+
+ search_value = NULL;
/* Get arguments and do error-checking */
- if (ARG_COUNT(ht) != 1 || getParameters(ht, ARG_COUNT(ht), &input) == FAILURE) {
+ if (ARG_COUNT(ht) < 1 || ARG_COUNT(ht) > 2 ||
+ getParameters(ht, ARG_COUNT(ht), &input, &search_value) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (input->type != IS_ARRAY) {
- zend_error(E_WARNING, "Argument to keys() should be an array");
+ zend_error(E_WARNING, "First argument to array_keys() should be an array");
return;
}
/* Initialize return array */
array_init(return_value);
+ add_key = 1;
/* Go through input array and add keys to the return array */
zend_hash_internal_pointer_reset(input->value.ht);
while(zend_hash_get_current_data(input->value.ht, (void **)&entry) == SUCCESS) {
- new_val = (zval *)emalloc(sizeof(zval));
- INIT_PZVAL(new_val);
-
- switch (zend_hash_get_current_key(input->value.ht, &string_key, &num_key)) {
- case HASH_KEY_IS_STRING:
- new_val->type = IS_STRING;
- new_val->value.str.val = string_key;
- new_val->value.str.len = strlen(string_key);
- zend_hash_next_index_insert(return_value->value.ht, &new_val,
- sizeof(zval *), NULL);
- break;
-
- case HASH_KEY_IS_LONG:
- new_val->type = IS_LONG;
- new_val->value.lval = num_key;
- zend_hash_next_index_insert(return_value->value.ht, &new_val,
- sizeof(zval *), NULL);
- break;
+ if (search_value != NULL) {
+ is_equal_function(&res, search_value, *entry);
+ add_key = zval_is_true(&res);
+ }
+
+ if (add_key) {
+ new_val = (zval *)emalloc(sizeof(zval));
+ INIT_PZVAL(new_val);
+
+ switch (zend_hash_get_current_key(input->value.ht, &string_key, &num_key)) {
+ case HASH_KEY_IS_STRING:
+ new_val->type = IS_STRING;
+ new_val->value.str.val = string_key;
+ new_val->value.str.len = strlen(string_key);
+ zend_hash_next_index_insert(return_value->value.ht, &new_val,
+ sizeof(zval *), NULL);
+ break;
+
+ case HASH_KEY_IS_LONG:
+ new_val->type = IS_LONG;
+ new_val->value.lval = num_key;
+ zend_hash_next_index_insert(return_value->value.ht, &new_val,
+ sizeof(zval *), NULL);
+ break;
+ }
}
zend_hash_move_forward(input->value.ht);
@@ -3206,7 +3220,7 @@
}
if (input->type != IS_ARRAY) {
- zend_error(E_WARNING, "Argument to values() should be an array");
+ zend_error(E_WARNING, "Argument to array_values() should be an array");
return;
}