我有一个列'pages‘,它的值类似于"1-3,4,5,6-10,12-15“等,我想按它们对我的数组进行排序。
但是结果不正确:"12-15,1-3,4,5,6-10“。
所以我想我要创建这样的虚拟财产:
protected $_virtual = ['proper_order'];
protected function _getProperOrder()
{
return intval(strtok($this->_properties['pages'], '-'));
}但是有没有办法使用Virtual Property对数组进行排序呢?
发布于 2017-11-02 17:35:00
好的。我来搞定。我使用了Collection,它起作用了。
$collection = new Collection($articles);
$result = $collection->sortBy('proper_order', SORT_ASC);https://stackoverflow.com/questions/47071596
复制相似问题