gpt4 book ai didi

php - 如何使用 PHP 对数组进行排序

转载 作者:可可西里 更新时间:2023-11-01 01:03:15 26 4
gpt4 key购买 nike

<分区>

假设我有一个这样的数组:

$arr_sequences = 
array('00-02', '02-03', '03-07', '23-03', '03-23', '07-11', '11-10', '11-11');

如何对数组进行排序,使值看起来像这样:

$arr_sequences = 
array('00-02', '02-03', '03-23', '23-03', '03-07', '07-11', '11-11', '11-10');

如果我们仔细观察,每个值都有一个除以 - 的 id(代码)
例如:

$arr_sequences[2] = '03-07'; // '07' as last code, then search another value with '07' in front of the value

那么下一个索引值应该是

$arr_sequences[5] = '07-11'; // '07' front, then search '11' as next value

目标是在不丢失任何长度的情况下对数组进行排序。

我试过树算法,但我无法让它工作。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com