@@ -1334,29 +1334,52 @@ PHP_FUNCTION(compact)
1334
1334
}
1335
1335
/* }}} */
1336
1336
1337
- /* {{{ proto array range(int low, int high)
1338
- Create an array containing the range of integers from low to high (inclusive) */
1337
+ /* {{{ proto array range(mixed low, mixed high)
1338
+ Create an array containing the range of integers or characters from low to high (inclusive) */
1339
1339
PHP_FUNCTION (range )
1340
1340
{
1341
1341
zval * * zlow , * * zhigh ;
1342
- int low , high ;
1343
1342
1344
1343
if (ZEND_NUM_ARGS () != 2 || zend_get_parameters_ex (2 ,& zlow ,& zhigh ) == FAILURE ) {
1345
1344
WRONG_PARAM_COUNT ;
1346
1345
}
1347
- convert_to_long_ex (zlow );
1348
- convert_to_long_ex (zhigh );
1349
- low = Z_LVAL_PP (zlow );
1350
- high = Z_LVAL_PP (zhigh );
1351
1346
1352
1347
/* allocate an array for return */
1353
1348
if (array_init (return_value ) == FAILURE ) {
1354
1349
RETURN_FALSE ;
1355
1350
}
1356
1351
1357
- for (; low <= high ; low ++ ) {
1358
- add_next_index_long (return_value , low );
1359
- }
1352
+ if (Z_TYPE_PP (zlow )== IS_STRING && Z_TYPE_PP (zhigh )== IS_STRING ) {
1353
+ char * low , * high ;
1354
+ convert_to_string_ex (zlow );
1355
+ convert_to_string_ex (zhigh );
1356
+ low = Z_STRVAL_PP (zlow );
1357
+ high = Z_STRVAL_PP (zhigh );
1358
+ if (* low > * high ) {
1359
+ for (; * low >= * high ; (* low )-- ) {
1360
+ add_next_index_stringl (return_value , low , 1 , 1 );
1361
+ }
1362
+ } else {
1363
+ for (; * low <= * high ; (* low )++ ) {
1364
+ add_next_index_stringl (return_value , low , 1 , 1 );
1365
+ }
1366
+ }
1367
+ } else {
1368
+ int low , high ;
1369
+ convert_to_long_ex (zlow );
1370
+ convert_to_long_ex (zhigh );
1371
+ low = Z_LVAL_PP (zlow );
1372
+ high = Z_LVAL_PP (zhigh );
1373
+ if (low > high ) {
1374
+ for (; low >= high ; low -- ) {
1375
+ add_next_index_long (return_value , low );
1376
+ }
1377
+ } else {
1378
+ for (; low <= high ; low ++ ) {
1379
+ add_next_index_long (return_value , low );
1380
+ }
1381
+ }
1382
+ }
1360
1383
}
1361
1384
/* }}} */
1362
1385
0 commit comments