doukong5394 2018-04-12 20:29
浏览 62
已采纳

在PHP中任意对数组中的对象进行排序

I have a function that is looping over a bunch of items that each look something like this:

[
{"Target":"col-one","Value":0.261},
{"Target":"col-two","Value":0.881},
{"Target":"col-three","Value":0.571},
{"Target":"col-four","Value":0}
]

I would like to re-order each item so that instead of going in ascending order, it goes something like col-one, col-four, col-three, col-two. Is there a relatively simple method that can accomplish this type of arbitrary sorting?

To be clear, I want the result to look like the following:

[
     {"Target":"col-one","Value":0.261}, 
     {"Target":"col-four","Value":0}, 
     {"Target":"col-three","Value":0.571}, 
     {"Target":"col-two","Value":0.881}

]

  • 写回答

3条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥30 关于#c++#的问题:用C++编程实现主存-Cache地址映射(附运行成功截图+注释)
      • ¥25 接口/特征方法的异常错误返回如何判断是否需要设计
      • ¥40 代码+预测分析,文件私信发哦(价格可商量)
      • ¥15 GAMES101 HW1 无法定义
      • ¥15 pycharm不管允许什么代码都出错,都会出现下面的情况。
      • ¥15 boost::integrate的用法
      • ¥20 51单片机输出pwm时无法调节频率,如何解决?
      • ¥15 DSP28335 AD采集正弦波
      • ¥50 pwwinauto调式修改
      • ¥30 关于#单片机#的问题:单片机基于51单片机开发计时器,使其实现以下功能:(1)开发板上四个独立按键分别控制计时器的启停、计时器的复位(按下计时值归零)、计时位切换、计时时间的递增