Skip to content

A free, self-hostable news aggregator…

sort results in find() method (#2874)

Eris2a6f6ee3f38b
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';