PHP:需要根据维度中的一个键对多维数组进行合并/排序
我希望我能够解释我正在尝试做的事情 - 并且真的希望有人能够提供帮助!这是我正在使用的数组
(
[0] => Array
(
[city] => Middletown
[state] => OH
[freq] => 146.610
[pl] => 77.0
[call] => W8BLV
[distance] => 0.0
[notes] => ottel
)
[1] => Array
(
[city] => Middletown
[state] => OH
[freq] => 146.715
[pl] =>
[call] => N8COZ
[distance] => 0.0
[notes] => ct
)
[2] => Array
(
[city] => Middletown
[state] => OH
[freq] => 147.315
[pl] => 77.0
[call] => W8JEU
[distance] => 0.0
[notes] => ottel
)
[3] => Array
(
[city] => Middletown
[state] => OH
[freq] => 443.5370
[pl] => 118.8
[call] => W8MUM
[distance] => 0.0
[notes] => oe oe
)
[4] => Array
(
[city] => Middletown
[state] => OH
[freq] => 444.4750
[pl] => 100.0
[call] => AG8Y
[distance] => 0.0
[notes] => ottel
)
[5] => Array
(
[city] => Middletown
[state] => OH
[freq] => 444.8250
[pl] => 77.0
[call] => W8BLV
[distance] => 0.0
[notes] => oel
)
[6] => Array
(
[city] => Monroe
[state] => OH
[freq] => 443.0870
[pl] =>
[call] => KC8ECK
[distance] => 4.3
[notes] => oep
)
[7] => Array
(
[city] => Franklin
[state] => OH
[freq] => 145.290
[pl] => 118.8
[call] => WB8ZVL
[distance] => 5.5
[notes] => o(ca)r
)
[8] => Array
(
[city] => Franklin
[state] => OH
[freq] => 442.4250
[pl] => 77.0
[call] => WE8N
[distance] => 5.5
[notes] => Oae(ca)
)
[9] => Array
(
[city] => Franklin
[state] => OH
[freq] => 443.1500
[pl] => 118.8
[call] => WB8ZVL
[distance] => 5.5
[notes] => o(ca)r
)
[10] => Array
(
[city] => Springboro
[state] => OH
[freq] => 145.490
[pl] => 77.0
[call] => W8CYE
[distance] => 8.9
[notes] => oe
)
)
我想要得到的输出需要是这样的:
$rpt[0] ="Middletown 146.61/77, 146.715, 147.315/77, 443.537/118.8, 444.475/100, 444.825/77";
$rpt[1] = "Monroe 443.087";
$rpt[2] = "Franklin 145.29/118.8, 442.425/77, 443.15/118.8";
$rpt[3] = "Springboro 145.49/77"
我最感兴趣的字段是城市、频率、pl - 如果你看第一个数组,我已经删除了输出数组上的尾随零。 还有几次我可能需要使用呼叫字段和注释字段,但如果有人可以给我指出正确的方向,我可能就能弄清楚 我需要的其余部分 - 调用字段和注释字段不会经常使用。 我已经尝试了几个不同的 foreach 循环,但我仍然是 PHP 的新手 - 而且我所做的并没有正确工作,而且我现在需要一些帮助。
预先感谢您的帮助, 勒罗伊,KD8BXP
I hope I will be able to explain what I'm trying to do - and really hope someone will be able to help! Here is the array I am working with
(
[0] => Array
(
[city] => Middletown
[state] => OH
[freq] => 146.610
[pl] => 77.0
[call] => W8BLV
[distance] => 0.0
[notes] => ottel
)
[1] => Array
(
[city] => Middletown
[state] => OH
[freq] => 146.715
[pl] =>
[call] => N8COZ
[distance] => 0.0
[notes] => ct
)
[2] => Array
(
[city] => Middletown
[state] => OH
[freq] => 147.315
[pl] => 77.0
[call] => W8JEU
[distance] => 0.0
[notes] => ottel
)
[3] => Array
(
[city] => Middletown
[state] => OH
[freq] => 443.5370
[pl] => 118.8
[call] => W8MUM
[distance] => 0.0
[notes] => oe oe
)
[4] => Array
(
[city] => Middletown
[state] => OH
[freq] => 444.4750
[pl] => 100.0
[call] => AG8Y
[distance] => 0.0
[notes] => ottel
)
[5] => Array
(
[city] => Middletown
[state] => OH
[freq] => 444.8250
[pl] => 77.0
[call] => W8BLV
[distance] => 0.0
[notes] => oel
)
[6] => Array
(
[city] => Monroe
[state] => OH
[freq] => 443.0870
[pl] =>
[call] => KC8ECK
[distance] => 4.3
[notes] => oep
)
[7] => Array
(
[city] => Franklin
[state] => OH
[freq] => 145.290
[pl] => 118.8
[call] => WB8ZVL
[distance] => 5.5
[notes] => o(ca)r
)
[8] => Array
(
[city] => Franklin
[state] => OH
[freq] => 442.4250
[pl] => 77.0
[call] => WE8N
[distance] => 5.5
[notes] => Oae(ca)
)
[9] => Array
(
[city] => Franklin
[state] => OH
[freq] => 443.1500
[pl] => 118.8
[call] => WB8ZVL
[distance] => 5.5
[notes] => o(ca)r
)
[10] => Array
(
[city] => Springboro
[state] => OH
[freq] => 145.490
[pl] => 77.0
[call] => W8CYE
[distance] => 8.9
[notes] => oe
)
)
The output I'm looking to get needs to be something like this:
$rpt[0] ="Middletown 146.61/77, 146.715, 147.315/77, 443.537/118.8, 444.475/100, 444.825/77";
$rpt[1] = "Monroe 443.087";
$rpt[2] = "Franklin 145.29/118.8, 442.425/77, 443.15/118.8";
$rpt[3] = "Springboro 145.49/77"
The fields I am most interested in are the city, freq, pl - And if you look at the first array, I have removed the trailing zeros on the output array.
There are also a couple of times when I may need to use the call field, and the notes field, but if someone can point me in the right direction I probably will be able to figure
the rest I need - the call field and notes field would not be used often.
I have tried a couple of different foreach loops, but I am still pretty much a novice at PHP - and what I've done hasn't worked correctly, and I'm at the point were I need a little help.
Thanks in advance for the help,
LeRoy, KD8BXP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是您需要的:
Here is what you need:
这样,
$output_array
最终将成为一个关联数组,其键是城市,其值是 freq+pl 数组列表:(不客气 - Amber,
KC9HTI)
编辑
运行上述代码后,您可以使用此代码获得您想要的最终格式:
$rpt
应该有您想要的数组。With this,
$output_array
will end up as an associative array whose keys are cities, and whose values are lists of freq+pl arrays:(And you're welcome - Amber,
KC9HTI
)Edit
Once you've run the above code, you can use this code to get the final format you wanted:
$rpt
should then have the array you want.