在我的PHP项目中,JSON里面是我保存的数据,每个数据的序列号是1.1,1.1.1,1.1.2,1.1.3,...,1.1.10。
当我排序时,我注意到1.1.10在1.1.1之后,而1.1.9还没有出现。
因为它是按字母顺序排序的。我不知道该怎么处理!
编辑:添加了示例JSON数据。
{
"2": {
"sirano": "1",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"124": {
"sirano": "1.1.1",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"125": {
"sirano": "1.1.2",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"126": {
"sirano": "1.1.3",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"127": {
"sirano": "1.1.4",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"128": {
"sirano": "1.1.5",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"129": {
"sirano": "1.1.6",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"130": {
"sirano": "1.1.7",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"131": {
"sirano": "1.1.8",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"132": {
"sirano": "1.1.9",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"133": {
"sirano": "1.1.10",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"134": {
"sirano": "1.2",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"135": {
"sirano": "1.3.1",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"136": {
"sirano": "1.3.2",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
},
"137": {
"sirano": "1.4.1",
"personal": "4",
"tarihler": {
"baslangic": "2022-11-10",
"bitis": "2022-11-17"
},
"ilerleme": "0"
}
}
$data = json_decode($proje->JSONData, true);
function order($a, $b)
{
return $a['sirano'] - $b['sirano'];
}
uasort($data, 'order');
我试过了,但结果很明显!请帮帮我,我快疯了!
2条答案
按热度按时间a8jjtwal1#
您需要在sort函数中使用
version_compare
函数:对于降序变化位
$b
abd$a
变量:qnakjoqk2#
x1E0F1x保持原始密钥,并且x1E1F1x使用“自然顺序”算法来比较2个字符串。