Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Collection order 方法不符合预期 #32

Open
wants to merge 2 commits into
base: 3.0
Choose a base branch
from

Conversation

kingofzihua
Copy link

fix: Collection order error
order 方法中最终使用 uasort 来进行排序 uasort 需要 0 1 -1 来表示顺序,旧代码中只有 0 1

example:

$data = [
            ['id' => 30, 'name' => '30'],
            ['id' => 29, 'name' => '29'],
            ['id' => 28, 'name' => '28'],
            ['id' => 27, 'name' => '27'],
            ['id' => 26, 'name' => '26'],
            ['id' => 25, 'name' => '25'],
            ['id' => 24, 'name' => '24'],
            ['id' => 23, 'name' => '23'],
        ];

       $res =  collect($data)->order('id');

       echo "<pre>";

       print_r($res->values()->toArray());

old:

Array
(
    [0] => Array
        (
            [id] => 23
            [name] => 23
        )

    [1] => Array
        (
            [id] => 25
            [name] => 25
        )

    [2] => Array
        (
            [id] => 24
            [name] => 24
        )

    [3] => Array
        (
            [id] => 26
            [name] => 26
        )

    [4] => Array
        (
            [id] => 27
            [name] => 27
        )

    [5] => Array
        (
            [id] => 28
            [name] => 28
        )

    [6] => Array
        (
            [id] => 29
            [name] => 29
        )

    [7] => Array
        (
            [id] => 30
            [name] => 30
        )

)

new:

Array
(
    [0] => Array
        (
            [id] => 23
            [name] => 23
        )

    [1] => Array
        (
            [id] => 24
            [name] => 24
        )

    [2] => Array
        (
            [id] => 25
            [name] => 25
        )

    [3] => Array
        (
            [id] => 26
            [name] => 26
        )

    [4] => Array
        (
            [id] => 27
            [name] => 27
        )

    [5] => Array
        (
            [id] => 28
            [name] => 28
        )

    [6] => Array
        (
            [id] => 29
            [name] => 29
        )

    [7] => Array
        (
            [id] => 30
            [name] => 30
        )

)

fix: Collection order error
order 方法中最终使用  uasort 来进行排序  uasort 需要 0 1 -1 来表示顺序,旧代码中只有 0 1

### example:

```php

$data = [
            ['id' => 30, 'name' => '30'],
            ['id' => 29, 'name' => '29'],
            ['id' => 28, 'name' => '28'],
            ['id' => 27, 'name' => '27'],
            ['id' => 26, 'name' => '26'],
            ['id' => 25, 'name' => '25'],
            ['id' => 24, 'name' => '24'],
            ['id' => 23, 'name' => '23'],
        ];

       $res =  collect($data)->order('id');

       echo "<pre>";

       print_r($res->values()->toArray());
```
### old:
```html
Array
(
    [0] => Array
        (
            [id] => 23
            [name] => 23
        )

    [1] => Array
        (
            [id] => 25
            [name] => 25
        )

    [2] => Array
        (
            [id] => 24
            [name] => 24
        )

    [3] => Array
        (
            [id] => 26
            [name] => 26
        )

    [4] => Array
        (
            [id] => 27
            [name] => 27
        )

    [5] => Array
        (
            [id] => 28
            [name] => 28
        )

    [6] => Array
        (
            [id] => 29
            [name] => 29
        )

    [7] => Array
        (
            [id] => 30
            [name] => 30
        )

)
```
### new:
```html
Array
(
    [0] => Array
        (
            [id] => 23
            [name] => 23
        )

    [1] => Array
        (
            [id] => 24
            [name] => 24
        )

    [2] => Array
        (
            [id] => 25
            [name] => 25
        )

    [3] => Array
        (
            [id] => 26
            [name] => 26
        )

    [4] => Array
        (
            [id] => 27
            [name] => 27
        )

    [5] => Array
        (
            [id] => 28
            [name] => 28
        )

    [6] => Array
        (
            [id] => 29
            [name] => 29
        )

    [7] => Array
        (
            [id] => 30
            [name] => 30
        )

)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant