给定的输入数组可能有点像这样:
$inputArr = [
[
'title' => 'Test0',
'desc' => 'Short Desc',
],
[
'title' => 'Test5',
'desc' => 'Short Desc',
],
[
'title' => 'Test0',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test0.5',
'desc' => 'Short Desc',
],
[
'title' => 'Test1',
'desc' => 'Short Desc',
],
[
'title' => 'Test1',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test1.5',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test3',
'desc' => 'Short Desc',
],
[
'title' => 'Test2',
'desc' => 'Short Desc',
],
[
'title' => 'Test3.75',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test3.25',
'desc' => 'Short Desc',
],
[
'title' => 'Test2',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test3',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test5',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test3.5',
'desc' => 'Short Desc',
],
[
'title' => 'Test4',
'desc' => 'Short Desc',
],
[
'title' => 'Test5',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test4.5',
'desc' => 'Short Desc',
],
[
'title' => 'Test4',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test5',
'desc' => 'Much Longer Than Short Desc',
],
];
结果数组必须只包含具有
title
desc
是除去除一个以外的所有字符串值时的最长字符串值
描述
与其他字符串长度值相等。
e、 g.最终输出应如下所示:
$resultArr = [
[
'title' => 'Test0',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test0.5',
'desc' => 'Short Desc',
],
[
'title' => 'Test1',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test1.5',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test2',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test3',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test3.25',
'desc' => 'Short Desc',
],
[
'title' => 'Test3.5',
'desc' => 'Short Desc',
],
[
'title' => 'Test3.75',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test4',
'desc' => 'Much Longer Than Short Desc',
],
[
'title' => 'Test4.5',
'desc' => 'Short Desc',
],
[
'title' => 'Test5',
'desc' => 'Much Longer Than Short Desc',
],
];
我试过几种不同的解决方案,但都不喜欢。不管我怎么做,这感觉就像是一个乱七八糟的问题,我觉得我错过了一个明显而优雅的解决方案。
我知道有人会有一个比我尝试过的排序、循环和过滤更干净的建议。