diff options
| author | 2020-04-04 06:27:48 -0400 | |
|---|---|---|
| committer | 2020-04-04 12:27:48 +0200 | |
| commit | 2a6f6ee3f38ba83b5b4c290494dc146644f3b583 (patch) | |
| tree | bfdb2325fe0b92fe31ce514e5a5ef7b9417edf46 /lib | |
| parent | c9b5e8b5271cc59598a4fbcea5ff93698aab2eea (diff) | |
sort results in find() method (#2874)
* sort results in find() method
* Update lib/lib_phpQuery.php
Co-Authored-By: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/lib_phpQuery.php | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/lib_phpQuery.php b/lib/lib_phpQuery.php index 53a3952cb..c4c9e395c 100644 --- a/lib/lib_phpQuery.php +++ b/lib/lib_phpQuery.php @@ -1796,6 +1796,14 @@ class phpQueryObject } $this->elements = $stack; } + + /** + * used for ordering results in find() + */ + private function cmpByLineNo($a , $b) { + return $a->getLineNo() <= $b->getLineNo() ? -1 : 1; + } + /** * Enter description here... * @@ -1958,6 +1966,7 @@ class phpQueryObject if (! $this->elementsContainsNode($node, $stack)) $stack[] = $node; } + usort($stack, array('phpQueryObject', 'cmpByLineNo')); $this->elements = $stack; return $this->newInstance(); } @@ -5700,4 +5709,4 @@ set_include_path( phpQuery::$plugins = new phpQueryPlugins(); // include bootstrap file (personal library config) if (file_exists(dirname(__FILE__).'/phpQuery/bootstrap.php')) - require_once dirname(__FILE__).'/phpQuery/bootstrap.php';
\ No newline at end of file + require_once dirname(__FILE__).'/phpQuery/bootstrap.php'; |
