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

Collection得order方法排序有问题 #31

Open
accpdyk opened this issue Aug 2, 2023 · 0 comments
Open

Collection得order方法排序有问题 #31

accpdyk opened this issue Aug 2, 2023 · 0 comments

Comments

@accpdyk
Copy link

accpdyk commented Aug 2, 2023

    public function order(string $field, string $order = 'asc')
    {
        return $this->sort(function ($a, $b) use ($field, $order) {
            $fieldA = $a[$field] ?? null;
            $fieldB = $b[$field] ?? null;

//
            return 'desc' == strtolower($order) ? intval($fieldB > $fieldA) : intval($fieldA > $fieldB);
        });
    }

代码中结果,只有0和1,没有-1得

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

No branches or pull requests

1 participant