根据多维数组中的键对数组进行排序并保留其他键值。 PHP
这是我的阵列。
Array ( [Data] => Array ( [0] => Array ( [recipeid] => 108 [recipe] => Rasams- the tongue ticklers ! [image] => No data [category] => Rasams and Soups ) [1] => Array ( [recipeid] => 44 [recipe] => Brain Booster- do you want to try it? [image] => brain-booster-do-you-44-HP-62.jpg [category] => Drinks and Smoothies ) [2] => Array ( [recipeid] => 36 [recipe] => Pineapple Grape Smoothy--a rare combo [image] => pineapple-grape-smoo-36-HP-62.jpg [category] => Drinks and Smoothies ) ) )
我必须根据[key]recipe值的字母顺序对[DATA]数组进行排序,并在排序后保留recipeid、图像、类别。
This is my array.
Array ( [Data] => Array ( [0] => Array ( [recipeid] => 108 [recipe] => Rasams- the tongue ticklers ! [image] => No data [category] => Rasams and Soups ) [1] => Array ( [recipeid] => 44 [recipe] => Brain Booster- do you want to try it? [image] => brain-booster-do-you-44-HP-62.jpg [category] => Drinks and Smoothies ) [2] => Array ( [recipeid] => 36 [recipe] => Pineapple Grape Smoothy--a rare combo [image] => pineapple-grape-smoo-36-HP-62.jpg [category] => Drinks and Smoothies ) ) )
I have to sort [DATA] array according to alphabetical order of [key]recipe's value, also preserve the recipeid, image, category after sorting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用usort。
Use usort.
您应该可以使用 usort() 来完成此操作。下面是一个基于 PHP 文档中给出的示例的示例,说明如何完成此操作。
You should be able to do this with usort(). Here's an example of how it could be done, based off of the example given in the PHP docs.