Browse Source

sort results in find() method (#2874)

* sort results in find() method

* Update lib/lib_phpQuery.php

Co-Authored-By: Alexandre Alapetite <alexandre@alapetite.fr>
Eris 6 years ago
parent
commit
2a6f6ee3f3
1 changed files with 10 additions and 1 deletions
  1. 10 1
      lib/lib_phpQuery.php

+ 10 - 1
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';
+	require_once dirname(__FILE__).'/phpQuery/bootstrap.php';