在我的代码中,我有一个集合对象。集合对象的一部分结构如下
"id" => 1
"rate" => "{"p_1":"1","p_2":"2","p_3":"2.3","p_4":"3.5"}"
"currency" => 1
"desc" => "TEST"
在上面的例子中,我有一个名为rate
的密钥,它有一个json字符串作为值。
我想要做的是按p_1
键中包含的值range
对集合对象进行排序。
答案 0 :(得分:2)
您必须在订购前解码JSON字符串:
Sub Multi_FindReplaceALL_pvc_replace_new()
'PURPOSE: Find & Replace a list of text/values throughout entire workbook
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long
fndList = Array("2 ft", "PVC", "390")
rplcList = Array("2 ft", "PVC", "290")
'Loop through each item in Array lists
For x = LBound(fndList) To UBound(fndList)
'Loop through each worksheet in ActiveWorkbook
For Each sht In ActiveWorkbook.Worksheets
sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht
Next x
End Sub
答案 1 :(得分:1)
使用sortBy()
对laravel中的集合进行排序
$collection->sortBy(function($item) {
return $item->rate->p_1;
});
此处$collection
是您的laravel结果,默认情况下,您可以使用collect
方法显式转换它
查看docs了解详情