Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120493 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85961 invoked from network); 31 May 2023 22:47:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 May 2023 22:47:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7176C180083 for ; Wed, 31 May 2023 15:47:55 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 31 May 2023 15:47:55 -0700 (PDT) Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5151934a4e3so459912a12.1 for ; Wed, 31 May 2023 15:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685573273; x=1688165273; h=message-id:in-reply-to:to:references:date:subject:mime-version:from :from:to:cc:subject:date:message-id:reply-to; bh=pl0mVi9rTHrJNYtFSizEC23JzbVzqhGvOTynWO9LSyY=; b=K9KDnoXEZLAckp6rfIMPZXNtCwJ+B3S+OWdQb1XQUMsK6rS8P8dNOOYMSTEJW3+gTB n5tKSukSs0kDwE69Yl0YVv9CKbZ4VKWqZyhG6BAo1FgdfR9fLyHEhgvIMTWI3nUw+tEq vAG45hutb7WkzVJBqf/xNL9xAvifRPwktoQuZD+vwSIxRNB4PjAL6KnvZql34pWbczbZ 3iLSNyfmaKCwzbhJtMz0z6ozZ9T88HTxU8ev3r0fBUjsLjjqhFK5W2pTz37y5rUpUAdw ZrT/+N3Py/R+oi6Wa6xUJc9Xp2abeh8FoZfXbdV7aPKdXnPoyeOETtY3016fzxljA9dd qXDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685573273; x=1688165273; h=message-id:in-reply-to:to:references:date:subject:mime-version:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pl0mVi9rTHrJNYtFSizEC23JzbVzqhGvOTynWO9LSyY=; b=Yfqbta1ge+p6HifgCr8jf1JdArjh/zqkQ4cgsgcR5mb+9DflVSXGSTbEDKaZBRWsAG yzJlgIaKJquB6/MPYlixFuNfnZh+Dp6eRTemNLAlBHRPO7UjtP2eWwwrkh9TTEY0UzGU HBcDji77bAZ7PU6dNuKUlnMovPuBSQ6koAHMtxOi6xclRCeVe5GK9Dc/5P2mvtBpQUaG k2zUr8xDg1Rs6UgtiXOzUFC/2i8vdYhvQg2IFmX4LEp+QLQrVc6Hm4yL9aCgV+UyrIOZ SzU5Rc8tS5CUDWtIVG1N7CbXda+PLd87ssStHwciwvOKurHu9PEJjnX0QrK3NtQJNiFJ btbg== X-Gm-Message-State: AC+VfDwH+l6aP76oTQh3I+zhxHcmrwiWUS3hFz5mtOc6oP3irGp1K4s7 z9omyZ7oD7QE6Em5+OQhbjVM1TV9DcE= X-Google-Smtp-Source: ACHHUZ6lM6aC+XG81Zd0dsnnwgNA7f+PlEDiLlzLoCR2WPNLvqgdKHB/X/+YaImLUrEwmzdeozEwCQ== X-Received: by 2002:a17:907:6d23:b0:973:d9ad:273f with SMTP id sa35-20020a1709076d2300b00973d9ad273fmr6243899ejc.46.1685573273018; Wed, 31 May 2023 15:47:53 -0700 (PDT) Received: from smtpclient.apple ([46.217.49.136]) by smtp.gmail.com with ESMTPSA id k17-20020a170906681100b0096f7105b3a6sm9563088ejr.189.2023.05.31.15.47.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2023 15:47:51 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_29B78402-96EE-4B8A-AD7F-A73CC80D8186" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) Date: Thu, 1 Jun 2023 00:47:38 +0200 References: <289E585B-EF8B-4B17-89BE-BE8295FD9FE1@gmail.com> <831B6DDD-B017-482A-9288-E31D44FC0298@gmail.com> To: php internals In-Reply-To: <831B6DDD-B017-482A-9288-E31D44FC0298@gmail.com> Message-ID: <155203BE-9037-4F24-9EBC-A46EAE2ACBF5@gmail.com> X-Mailer: Apple Mail (2.3731.600.7) Subject: Re: [RFC] [Discussion] Add new function `array_group` From: buritomath@gmail.com (Boro Sitnikovski) --Apple-Mail=_29B78402-96EE-4B8A-AD7F-A73CC80D8186 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 30.5.2023, at 15:13, Boro Sitnikovski wrote: >=20 > Updated the patch: added a test about increasing subsequences example, = and a minor bugfix. >=20 > >=20 >=20 >> On 30.5.2023, at 13:34, Boro Sitnikovski = wrote: >>=20 >> Hello all, >>=20 >> As per the How To Create an RFC = instructions, I am sending this e-mail in order to get your feedback on = my proposal. >>=20 >> I propose introducing a function to PHP core named `array_group`. = This function takes an array and a function and returns an array that = contains arrays - groups of consecutive elements. This is very similar = to Haskell's `groupBy` function = . >>=20 >> For some background as to why - usually, when people want to do = grouping in PHP, they use hash maps, so something like: >>=20 >> ``` >> > $array =3D [ >> [ 'id' =3D> 1, 'value' =3D> 'foo' ], >> [ 'id' =3D> 1, 'value' =3D> 'bar' ], >> [ 'id' =3D> 2, 'value' =3D> 'baz' ], >> ]; >>=20 >> $groups =3D []; >> foreach ( $array as $element ) { >> $groups[ $element['id'] ][] =3D $element; >> } >>=20 >> var_dump( $groups ); >> ``` >>=20 >> This can now be achieved as follows (not preserving keys): >>=20 >> ``` >> > $array =3D [ >> [ 'id' =3D> 1, 'value' =3D> 'foo' ], >> [ 'id' =3D> 1, 'value' =3D> 'bar' ], >> [ 'id' =3D> 2, 'value' =3D> 'baz' ], >> ]; >>=20 >> $groups =3D array_group( $array, function( $a, $b ) { >> return $a['id'] =3D=3D $b['id']; >> } ); >> ``` >>=20 >> The disadvantage of the first approach is that we are only limited to = using equality check, and we cannot group by, say, `<` or other = functions. >> Similarly, the advantage of the first approach is that the keys are = preserved, and elements needn't be consecutive. >>=20 >> In any case, I think a utility function such as `array_group` will be = widely useful. >>=20 >> Please find attached a patch with a proposed implementation. Curious = about your feedback. >>=20 >> Best, >>=20 >> Boro Sitnikovski >>=20 >> >=20 Thank you all for the comments. I agree that there are many ways to do = grouping, but based on the discussion here, I think we discussed two = main grouping cases: 1. The grouping that JavaScript/.NET/Lodash/Scala/etc. do (this should = be the default of `array_group`) 2. The grouping that Haskell does, the one I proposed earlier (this can = be altered in a flag within `array_group`) Based on this, I'd like to adjust my initial proposal, where we would = have the following function: `function array_group(array $array, = callable $callback, bool $consecutive_pairs =3D false): array {}` If the argument `consecutive_pairs` is false, it will use the function's = return value to do the grouping ($callback accepting single element in = this case) Otherwise, it will use the function's boolean return value to check if = two consecutive elements need to be grouped ($callback accepting two = elements in this case) (This approach seems to be consistent with `array_filter` in the sense = the callback accepts one or two arguments) With a few example usages: ``` var_dump( array_group($arr1, function( $x ) { return (string) strlen( $x ); } ) ); // Producing ['3' =3D> ['one', 'two'], '5' =3D> ['three']] ``` Another one: ``` $arr =3D [-1,2,-3,-4,2,1,2,-3,1,1,2]; $groups =3D array_group( $arr, function( $p1, $p2 ) { return ($p1 > 0) =3D=3D ($p2 > 0); } ); // Producing [[-1],[2],[-3,-4],[2,1,2],[-3],[1,1,2]] ``` I believe this proposal captures many use cases, beyond the examples we = discussed. Curious about any other thoughts. I'm also attaching a PoC patch that implements this. =EF=BF=BC= --Apple-Mail=_29B78402-96EE-4B8A-AD7F-A73CC80D8186 Content-Type: multipart/mixed; boundary="Apple-Mail=_D414342E-4D09-47D4-8864-96E57D12220F" --Apple-Mail=_D414342E-4D09-47D4-8864-96E57D12220F Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
On = 30.5.2023, at 15:13, Boro Sitnikovski <buritomath@gmail.com> = wrote:

Updated the patch: added a test about = increasing subsequences example, and a minor = bugfix.

<array_group.patch><= /span>


On = 30.5.2023, at 13:34, Boro Sitnikovski <buritomath@gmail.com> = wrote:

Hello = all,

As per the How To Create an = RFC instructions, I am sending this e-mail in order to get your = feedback on my proposal.

I propose introducing = a function to PHP core named `array_group`. This function takes an array = and a function and returns an array that contains arrays - groups of = consecutive elements. This is very similar to Haskell's `groupBy` function.

For some = background as to why - usually, when people want to do grouping in PHP, = they use hash maps, so something = like:

```
<?php
$arra= y =3D [
[ 'id' =3D> 1, 'value' =3D> 'foo' = ],
= [ 'id' =3D> 1, 'value' =3D> 'bar' ],
[ 'id' = =3D> 2, 'value' =3D> 'baz' = ],
];

$groups =3D = [];
foreach ( $array as $element ) {
    = $groups[ $element['id'] ][] =3D = $element;
}

var_dump( $groups = );
```

This can now be achieved = as follows (not preserving = keys):

```
<?php
$arr= ay =3D [
[ 'id' =3D> 1, 'value' =3D> 'foo' = ],
= [ 'id' =3D> 1, 'value' =3D> 'bar' ],
[ 'id' = =3D> 2, 'value' =3D> 'baz' = ],
];

$groups =3D array_group( = $array, function( $a, $b ) {
return $a['id'] =3D=3D = $b['id'];
} = );
```

The disadvantage of the = first approach is that we are only limited to using equality check, and = we cannot group by, say, `<` or other functions.
Similarly, = the advantage of the first approach is that the keys are preserved, and = elements needn't be consecutive.

In any case, I = think a utility function such as `array_group` will be widely = useful.

Please find attached a patch with a = proposed implementation. Curious about your = feedback.

Best,


<array_group.patch><= /span>

<= /blockquote>
Thank you all for the comments. I = agree that there are many ways to do grouping, but based on the = discussion here, I think we discussed two main grouping = cases:

1. The grouping that = JavaScript/.NET/Lodash/Scala/etc. do (this should be the default of = `array_group`)
2. The grouping that Haskell does, the one I = proposed earlier (this can be altered in a flag within = `array_group`)

Based on this, I'd like to = adjust my initial proposal, where we would have the following function: = `function array_group(array $array, callable $callback, bool = $consecutive_pairs =3D false): array {}`

If the = argument `consecutive_pairs` is false, it will use the function's return = value to do the grouping ($callback accepting single element in this = case)
Otherwise, it will use the function's boolean return = value to check if two consecutive elements need to be grouped ($callback = accepting two elements in this case)

(This = approach seems to be consistent with `array_filter` in the sense the = callback accepts one or two arguments)

With a = few example usages:

```
var_dump( = array_group($arr1, function( $x ) {
return = (string) strlen( $x );
} ) );
// Producing ['3' = =3D> ['one', 'two'], '5' =3D> = ['three']]
```

Another = one:

```
$arr =3D = [-1,2,-3,-4,2,1,2,-3,1,1,2];

$groups =3D = array_group( $arr, function( $p1, $p2 ) {
  return ($p1 = > 0) =3D=3D ($p2 > 0);
} );
// Producing = [[-1],[2],[-3,-4],[2,1,2],[-3],[1,1,2]]
```

=
I believe this proposal captures many use cases, beyond the = examples we discussed. Curious about any other = thoughts.

I'm also attaching a PoC patch that = implements = this.

= --Apple-Mail=_D414342E-4D09-47D4-8864-96E57D12220F Content-Disposition: attachment; filename=array_group.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="array_group.patch" Content-Transfer-Encoding: 7bit diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 5726c8a919..c462de2850 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -1087,6 +1087,10 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, _ZEND_HASH_FOREACH_VAL(ht); \ _val = _z; +#define ZEND_HASH_FOREACH_VAL_FROM(ht, _val, _from) \ + ZEND_HASH_FOREACH_FROM(ht, 0, _from); \ + _val = _z; + #define ZEND_HASH_REVERSE_FOREACH_VAL(ht, _val) \ _ZEND_HASH_REVERSE_FOREACH_VAL(ht); \ _val = _z; diff --git a/ext/standard/array.c b/ext/standard/array.c index 46c2c882b8..918aa54263 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -6394,6 +6394,114 @@ PHP_FUNCTION(array_map) } /* }}} */ +/* {{{ Groups elements from the array via the callback. */ +PHP_FUNCTION(array_group) +{ + zval *array; + zend_fcall_info fci; + zend_fcall_info_cache fci_cache = empty_fcall_info_cache; + + zval args[2]; + zval *curr_val; + zval chunk; + zval retval; + bool consecutive_pairs = 0; + + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ARRAY(array) + Z_PARAM_FUNC(fci, fci_cache) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(consecutive_pairs) + ZEND_PARSE_PARAMETERS_END(); + + if (zend_hash_num_elements(Z_ARRVAL_P(array)) == 0) { + RETVAL_EMPTY_ARRAY(); + return; + } + + array_init(return_value); + fci.retval = &retval; + + if (consecutive_pairs) { + zval *prev_val; + + fci.param_count = 2; + + // The array is guaranteed to have at least one element. + prev_val = ZEND_HASH_ELEMENT(Z_ARRVAL_P(array), 0); + + // Generate the initial group. + array_init(&chunk); + zend_hash_next_index_insert_new(Z_ARRVAL_P(&chunk), prev_val); + + ZEND_HASH_FOREACH_VAL_FROM(Z_ARRVAL_P(array), curr_val, 1) { + ZVAL_COPY(&args[0], prev_val); + ZVAL_COPY(&args[1], curr_val); + fci.params = args; + + if (zend_call_function(&fci, &fci_cache) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { + int retval_true; + + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); + + retval_true = zend_is_true(&retval); + + zval_ptr_dtor(&retval); + + // Perform grouping - add the current group and create a new one. + if (!retval_true) { + zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &chunk); + array_init(&chunk); + } + + zend_hash_next_index_insert_new(Z_ARRVAL_P(&chunk), curr_val); + + prev_val = curr_val; + } else { + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); + RETURN_NULL(); + } + } ZEND_HASH_FOREACH_END(); + + // Add the last group. + zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &chunk); + } else { + zval *group; + + fci.param_count = 1; + + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), curr_val) { + ZVAL_COPY(&args[0], curr_val); + fci.params = args; + + if (zend_call_function(&fci, &fci_cache) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { + if (Z_TYPE_P(&retval) != IS_STRING) { + php_error_docref(NULL, E_WARNING, "Argument #1 must be string, %s given", zend_zval_value_name(&retval)); + RETVAL_EMPTY_ARRAY(); + return; + } + group = zend_hash_find(Z_ARRVAL_P(return_value), Z_STR_P(&retval)); + if (group == NULL) { + array_init(&chunk); + group = &chunk; + zend_hash_add_new(Z_ARRVAL_P(return_value), Z_STR_P(&retval), group); + } + + zend_hash_next_index_insert(Z_ARRVAL_P(group), curr_val); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&retval); + + } else { + zval_ptr_dtor(&args[0]); + RETURN_NULL(); + } + } ZEND_HASH_FOREACH_END(); + } +} +/* }}} */ + /* {{{ Checks if the given key or index exists in the array */ PHP_FUNCTION(array_key_exists) { diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index effb05ff9f..395ec67fc0 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -1870,6 +1870,8 @@ function array_filter(array $array, ?callable $callback = null, int $mode = 0): function array_map(?callable $callback, array $array, array ...$arrays): array {} +function array_group(array $array, callable $callback, bool $consecutive_pairs = false): array {} + /** * @param string|int $key * @compile-time-eval diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 5612ee2186..dce035fd6b 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -342,6 +342,12 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_map, 0, 2, IS_ARRAY, 0) ZEND_ARG_VARIADIC_TYPE_INFO(0, arrays, IS_ARRAY, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_group, 0, 2, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, array, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consecutive_pairs, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_key_exists, 0, 2, _IS_BOOL, 0) ZEND_ARG_INFO(0, key) ZEND_ARG_TYPE_INFO(0, array, IS_ARRAY, 0) @@ -2292,6 +2298,7 @@ ZEND_FUNCTION(array_product); ZEND_FUNCTION(array_reduce); ZEND_FUNCTION(array_filter); ZEND_FUNCTION(array_map); +ZEND_FUNCTION(array_group); ZEND_FUNCTION(array_key_exists); ZEND_FUNCTION(array_chunk); ZEND_FUNCTION(array_combine); @@ -2915,6 +2922,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(array_reduce, arginfo_array_reduce) ZEND_FE(array_filter, arginfo_array_filter) ZEND_FE(array_map, arginfo_array_map) + ZEND_FE(array_group, arginfo_array_group) ZEND_SUPPORTS_COMPILE_TIME_EVAL_FE(array_key_exists, arginfo_array_key_exists) ZEND_FALIAS(key_exists, array_key_exists, arginfo_key_exists) ZEND_SUPPORTS_COMPILE_TIME_EVAL_FE(array_chunk, arginfo_array_chunk) diff --git a/ext/standard/tests/array/array_group_basic.phpt b/ext/standard/tests/array/array_group_basic.phpt new file mode 100644 index 0000000000..582c4ff22a --- /dev/null +++ b/ext/standard/tests/array/array_group_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test array_group() function : basic functionality +--FILE-- + +--EXPECT-- +*** Testing array_group() : basic functionality *** +-- With an array of three elements -- +array(2) { + ["3"]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + ["5"]=> + array(1) { + [0]=> + string(5) "three" + } +} +-- With an empty array -- +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_group_consecutive_pairs.phpt b/ext/standard/tests/array/array_group_consecutive_pairs.phpt new file mode 100644 index 0000000000..a8193f3212 --- /dev/null +++ b/ext/standard/tests/array/array_group_consecutive_pairs.phpt @@ -0,0 +1,115 @@ +--TEST-- +Test array_group() function : basic functionality (consecutive pairs) +--FILE-- +name == $b->name; +} + +$arr1 = array(1, 2, 3); + +echo "-- With an integer array for < --\n"; +var_dump( array_group($arr1, 'less_than', true) ); + +echo "-- With an integer array for == --\n"; +var_dump( array_group($arr1, 'equal', true) ); + +echo "-- With an empty array for == --\n"; +var_dump( array_group(array(), 'equal', true) ); + +echo "-- With a singleton integer array for == --\n"; +var_dump( array_group(array(1), 'equal', true) ); + +$obj1 = (object)array('id'=>3,'name'=>'foo'); +$obj2 = (object)array('id'=>4,'name'=>'foo'); +$obj3 = (object)array('id'=>5,'name'=>'baz'); + +echo "-- With an integer array of objects for == --\n"; +var_dump( array_group(array($obj1, $obj2, $obj3), 'equal_obj', true) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_group() : basic functionality (consecutive pairs) *** +-- With an integer array for < -- +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +-- With an integer array for == -- +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +-- With an empty array for == -- +array(0) { +} +-- With a singleton integer array for == -- +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +-- With an integer array of objects for == -- +array(2) { + [0]=> + array(2) { + [0]=> + object(stdClass)#1 (2) { + ["id"]=> + int(3) + ["name"]=> + string(3) "foo" + } + [1]=> + object(stdClass)#2 (2) { + ["id"]=> + int(4) + ["name"]=> + string(3) "foo" + } + } + [1]=> + array(1) { + [0]=> + object(stdClass)#3 (2) { + ["id"]=> + int(5) + ["name"]=> + string(3) "baz" + } + } +} +Done diff --git a/ext/standard/tests/array/array_group_incr_subseqs.phpt b/ext/standard/tests/array/array_group_incr_subseqs.phpt new file mode 100644 index 0000000000..245387862f --- /dev/null +++ b/ext/standard/tests/array/array_group_incr_subseqs.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_group() function : increasing subsequences +--FILE-- + +--EXPECT-- +*** Testing array_group() : increasing subsequences *** +array(4) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + array(3) { + [0]=> + int(0) + [1]=> + int(4) + [2]=> + int(5) + } + [3]=> + array(1) { + [0]=> + int(2) + } +} +Done --Apple-Mail=_D414342E-4D09-47D4-8864-96E57D12220F Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii
--Apple-Mail=_D414342E-4D09-47D4-8864-96E57D12220F-- --Apple-Mail=_29B78402-96EE-4B8A-AD7F-A73CC80D8186--