Skip to content

Commit e53e3fd

Browse files
Added sortByCallable method
1 parent b225c52 commit e53e3fd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Jsonq.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,27 @@ public function sortBy($column, $order = 'asc')
435435
return $this;
436436
}
437437

438+
/**
439+
* Sort prepared data using a custom sort function.
440+
*
441+
* @param callable $sortFunc
442+
*
443+
* @return object|array|null
444+
* @throws ConditionNotAllowedException
445+
*/
446+
public function sortByCallable(callable $sortFunc)
447+
{
448+
$this->prepare();
449+
450+
if (!is_array($this->_map)) {
451+
return $this;
452+
}
453+
454+
usort($this->_map, $sortFunc);
455+
456+
return $this;
457+
}
458+
438459
/**
439460
* Sort an array value
440461
*

0 commit comments

Comments
 (0)