如何判断数组的值是否按顺序排序?

WBOY
Release: 2016-06-06 20:28:33
Original
2143 people have browsed it

<code>$array = array(
    '1'=>1,
    '2'=>2,
    '3'=>3
);</code>
Copy after login
Copy after login

这样就是顺序排序

<code>$array = array(
    '1'=>1,
    '2'=>3,
    '3'=>2
);</code>
Copy after login
Copy after login

这样是错误的顺序排序

如何判断?

回复内容:

<code>$array = array(
    '1'=>1,
    '2'=>2,
    '3'=>3
);</code>
Copy after login
Copy after login

这样就是顺序排序

<code>$array = array(
    '1'=>1,
    '2'=>3,
    '3'=>2
);</code>
Copy after login
Copy after login

这样是错误的顺序排序

如何判断?

我不是很确定题主的问题。按照我的理解,题主想问的是数组是否是有序的。
如果是这样的话,把数组遍历一遍就行了。如果遇上某个元素比它之后的元素小,说明是无序的。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!