derick Wed Sep 15 07:51:56 2004 EDT
Modified files: (Branch: PHP_5_0)
/php-src NEWS
/php-src/ext/standard array.c
Log:
- MFH: Added new boolean (fourth) parameter to array_slice() that turns on the
preservation of keys in the returned array.
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1760.2.72&r2=1.1760.2.73&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1760.2.72 php-src/NEWS:1.1760.2.73
--- php-src/NEWS:1.1760.2.72 Tue Sep 14 08:13:38 2004
+++ php-src/NEWS Wed Sep 15 07:51:56 2004
@@ -1,6 +1,8 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2004, PHP 5.0.2
+- Added new boolean (fourth) parameter to array_slice() that turns on the
+ preservation of keys in the returned array. (Derick)
- Added the sorting flag SORT_LOCALE_STRING to the sort() functions which makes
them sort based on the current locale. (Derick)
- Added interface_exists() and make class_exists() only return true for real
http://cvs.php.net/diff.php/php-src/ext/standard/array.c?r1=1.266.2.4&r2=1.266.2.5&ty=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.266.2.4 php-src/ext/standard/array.c:1.266.2.5
--- php-src/ext/standard/array.c:1.266.2.4 Sat Sep 11 10:20:55 2004
+++ php-src/ext/standard/array.c Wed Sep 15 07:51:56 2004
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.266.2.4 2004/09/11 14:20:55 derick Exp $ */
+/* $Id: array.c,v 1.266.2.5 2004/09/15 11:51:56 derick Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -2090,7 +2090,8 @@
zval **input, /* Input array */
**offset, /* Offset to get elements from */
**length, /* How many elements to get */
- **entry; /* An array entry */
+ **entry, /* An array entry */
+ **z_preserve_keys; /* Whether to preserve keys while copying to the
new array or not */
int offset_val, /* Value of the offset argument */
length_val, /* Value of the length argument */
num_in, /* Number of elements in the input array */
@@ -2101,10 +2102,11 @@
uint string_key_len;
ulong num_key;
HashPosition hpos;
+ zend_bool preserve_keys = 0;
/* Get the arguments and do error-checking */
argc = ZEND_NUM_ARGS();
- if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &input, &offset,
&length)) {
+ if (argc < 2 || argc > 4 || zend_get_parameters_ex(argc, &input, &offset,
&length, &z_preserve_keys)) {
WRONG_PARAM_COUNT;
}
@@ -2118,12 +2120,17 @@
is not passed */
convert_to_long_ex(offset);
offset_val = Z_LVAL_PP(offset);
- if (argc == 3) {
+ if (argc >= 3) {
convert_to_long_ex(length);
length_val = Z_LVAL_PP(length);
} else {
length_val = zend_hash_num_elements(Z_ARRVAL_PP(input));
}
+
+ if (ZEND_NUM_ARGS() > 3) {
+ convert_to_boolean_ex(z_preserve_keys);
+ preserve_keys = Z_BVAL_PP(z_preserve_keys);
+ }
/* Initialize returned array */
array_init(return_value);
@@ -2167,8 +2174,12 @@
break;
case HASH_KEY_IS_LONG:
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value),
-
entry, sizeof(zval *), NULL);
+ if (preserve_keys)
+
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key,
+
entry, sizeof(zval *), NULL);
+ else
+
zend_hash_next_index_insert(Z_ARRVAL_P(return_value),
+
entry, sizeof(zval *), NULL);
break;
}
pos++;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php